public void AccesTokenProvider_ThrowsArgumentNullException_ClaimsDictionaryIsNull()
        {
            var headerProviderMock = new Mock <IHeaderProvider>();

            var payloadProviderMock = new Mock <IPayloadProvider>();

            var tokenProvider = new AccessTokenProvider(headerProviderMock.Object, payloadProviderMock.Object);

            Assert.Throws <ArgumentNullException>(() => tokenProvider.GetAccessToken(It.IsAny <DateTime>(), It.IsAny <Dictionary <string, object> >()));
        }
示例#2
0
        static void Main(string[] args)
        {
            try
            {
                var UserEmail    = ConfigurationManager.AppSettings["AAD:UserEmail"];
                var UserPassword = ConfigurationManager.AppSettings["AAD:UserPassword"];
                var resource     = ConfigurationManager.AppSettings["AAD.Resource"];


                Console.WriteLine("{0} - Connecting as user:{1}", DateTime.Now, UserEmail);


                var accessToken = AccessTokenProvider.GetAccessToken(resource, UserEmail, UserPassword);

                //Calling Graph Client
                var delegateAuthProvider = new DelegateAuthenticationProvider((requestMessage) =>
                {
                    requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken.Token);

                    return(Task.FromResult(0));
                });

                var graphClient = new GraphServiceClient(delegateAuthProvider);

                Console.WriteLine("Reading top 20 emails......");

                var mailResults = graphClient.Me.MailFolders.Inbox.Messages.Request()
                                  .OrderBy("receivedDateTime DESC")
                                  .Select(m => new { m.Subject, m.ReceivedDateTime, m.From })
                                  .Top(20)
                                  .GetAsync()
                                  .Result;


                foreach (var msg in mailResults.CurrentPage)
                {
                    Console.WriteLine("Subject: {0}<br/>", msg.Subject);
                }

                Console.WriteLine();
                Console.WriteLine("Done. Press any key to continue....");
            }
            catch (Exception err)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error:{0}", err.Message);
                while ((err = err.InnerException) != null)
                {
                    Console.WriteLine(err.Message);
                }
            }

            Console.ReadKey();
        }
        public void AccessTokenProvider_GetAccessToken_ReturnsTokenWithExpirationDataSet()
        {
            var expirationData     = new DateTime(2018, 04, 14);
            var header             = new JwtHeader();
            var headerProviderMock = new Mock <IHeaderProvider>();

            headerProviderMock.Setup(x => x.GetHeader()).Returns(header);

            var payload             = new JwtPayload();
            var payloadProviderMock = new Mock <IPayloadProvider>();

            payloadProviderMock.Setup(x => x.GetPayload(It.IsAny <DateTime>(), It.IsAny <Dictionary <string, object> >())).Returns(payload);

            var tokenProvider = new AccessTokenProvider(headerProviderMock.Object, payloadProviderMock.Object);

            var token = tokenProvider.GetAccessToken(expirationData, new Dictionary <string, object>());

            Assert.Equal(expirationData, token.ExpirationDate);
        }
示例#4
0
 public void Login(AccessTokenProvider provider) => Login(provider.GetAccessToken());