public async Task <ActionResult> LeadAppointment(string leadID)
        {
            var client = await GetExchangeClient();

            LeadAppointmentViewModel vm = new LeadAppointmentViewModel();

            vm.leadID = leadID;

            //look up lead information

            //get authorization token
            Authenticator authenticator = new Authenticator();
            var           authInfo      = await authenticator.AuthenticateAsync(ExchangeResourceId);

            HttpClient httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri(ExchangeResourceId);
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await authInfo.GetAccessToken());

            var response = httpClient.GetAsync("/ews/odata/Me/Inbox/Messages('" + leadID + "')").Result;

            if (response.StatusCode == HttpStatusCode.OK)
            {
                var responseContent = await response.Content.ReadAsStringAsync();

                var message = JObject.Parse(responseContent).ToObject <Message>();

                vm.appointmentMessage = message.BodyPreview;
            }

            return(View(vm));
        }
        private async Task <Message> GetMessageByID(string messageID)
        {
            //get authorization token
            Authenticator authenticator = new Authenticator();
            var           authInfo      = await authenticator.AuthenticateAsync(ExchangeResourceId);

            //send request through HttpClient
            HttpClient httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri(ExchangeResourceId);

            //add authorization header
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await authInfo.GetAccessToken());

            //send request
            var response = httpClient.GetAsync("/ews/odata/Me/Inbox/Messages('" + messageID + "')").Result;

            //process response
            if (response.StatusCode == HttpStatusCode.OK)
            {
                var responseContent = await response.Content.ReadAsStringAsync();

                var message = JObject.Parse(responseContent).ToObject <Message>();

                return(message);
            }

            return(null);
        }
        public static async Task<AadGraphClient> EnsureClientCreated(Context context)
        {
            Authenticator authenticator = new Authenticator(context);
            var authInfo = await authenticator.AuthenticateAsync(AadGraphResource);

            return new AadGraphClient(new Uri(AadGraphResource + authInfo.IdToken.TenantId), authInfo.GetAccessToken);
        }
        private async Task <bool> DeleteMessage(string messageID)
        {
            //get authorization token
            Authenticator authenticator = new Authenticator();
            var           authInfo      = await authenticator.AuthenticateAsync(ExchangeResourceId);

            //send request through HttpClient
            HttpClient httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri(ExchangeResourceId);

            //add authorization header
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await authInfo.GetAccessToken());

            //send request
            var response = httpClient.DeleteAsync("/ews/odata/Me/Inbox/Messages('" + messageID + "')").Result;

            if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.NoContent)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #5
0
 public async Task Authenticate_NullIdentityTest()
 {
     var connectionManager = Mock.Of <IConnectionManager>();
     var credentialsCache  = Mock.Of <ICredentialsCache>();
     var authenticator     = new Authenticator(new TokenCacheAuthenticator(new CloudTokenAuthenticator(connectionManager, TestIotHub), new NullCredentialsCache(), TestIotHub), "your-device", credentialsCache);
     await Assert.ThrowsAsync <ArgumentNullException>(() => authenticator.AuthenticateAsync(null));
 }
        public static async Task<ExchangeClient> GetClientInstance()
        {
            Authenticator authenticator = new Authenticator();
            var authInfo = await authenticator.AuthenticateAsync(ExchangeResourceId);

            return new ExchangeClient(new Uri(ExchangeServiceRoot), authInfo.GetAccessToken);
        }
Example #7
0
        private static async Task <ExchangeClient> EnsureClientCreated()
        {
            Authenticator authenticator = new Authenticator();
            var           authInfo      = await authenticator.AuthenticateAsync(ExchangeResourceId);

            return(new ExchangeClient(new Uri(ExchangeServiceRoot), authInfo.GetAccessToken));
        }
        private static async Task<ExchangeClient> EnsureClientCreated()
        {
            Authenticator authenticator = new Authenticator();
            var authInfo = await authenticator.AuthenticateAsync(ExchangeResourceId);

            return new ExchangeClient(new Uri(ExchangeServiceRoot), authInfo.GetAccessToken);
        }
Example #9
0
        private static async Task <AadGraphClient> EnsureClientCreated()
        {
            Authenticator authenticator = new Authenticator();
            var           authInfo      = await authenticator.AuthenticateAsync(AadGraphResource);

            return(new AadGraphClient(new Uri(AadGraphResource + authInfo.IdToken.TenantId), authInfo.GetAccessToken));
        }
Example #10
0
        public static async Task EnsureClientCreated(Context context)
        {
            Authenticator authenticator = new Authenticator(context);
            var           authInfo      = await authenticator.AuthenticateAsync(ExchangeResourceId);

            userId         = authInfo.IdToken.UPN;
            exchangeClient = new ExchangeClient(new Uri(ExchangeServiceRoot), authInfo.GetAccessToken);
        }
        private static async Task<SharePointClient> EnsureClientCreated()
        {
            Authenticator authenticator = new Authenticator();
            var authInfo = await authenticator.AuthenticateAsync(MyFilesCapability, ServiceIdentifierKind.Capability);

            // Create the MyFiles client proxy:
            return new SharePointClient(authInfo.ServiceUri, authInfo.GetAccessToken);
        }
Example #12
0
        private async Task EnsureClientCreated()
        {
            var authenticator = new Authenticator();
            var result        = await authenticator.AuthenticateAsync("https://outlook.office365.com/");

            // Create a client proxy:
            this.client = new ExchangeClient(new Uri("https://outlook.office365.com/ews/odata"), result.GetAccessToken);
        }
Example #13
0
        public static async Task <SharePointClient> EnsureClientCreated(UIViewController context)
        {
            Authenticator authenticator = new Authenticator(context);
            var           authInfo      = await authenticator.AuthenticateAsync(SharePointResourceId, ServiceIdentifierKind.Resource);

            // Create the SharePoint client proxy:
            return(new SharePointClient(new Uri(SharePointServiceRoot), authInfo.GetAccessToken));
        }
Example #14
0
        public static async Task<SharePointClient> EnsureClientCreated(UIViewController context)
        {
            Authenticator authenticator = new Authenticator(context);
            var authInfo = await authenticator.AuthenticateAsync(SharePointResourceId, ServiceIdentifierKind.Resource);

            // Create the SharePoint client proxy:
            return new SharePointClient(new Uri(SharePointServiceRoot), authInfo.GetAccessToken);
        }
Example #15
0
        public async Task Authenticate_NonNullIdentityTest()
        {
            var connectionManager = Mock.Of <IConnectionManager>();
            var clientCredentials = Mock.Of <IClientCredentials>(c => c.Identity == Mock.Of <IModuleIdentity>(i => i.DeviceId == "my-device"));

            var authenticator = new Authenticator(new TokenCredentialsAuthenticator(connectionManager, new NullCredentialsStore(), TestIotHub), "your-device");

            Assert.Equal(false, await authenticator.AuthenticateAsync(clientCredentials));
        }
Example #16
0
        private async Task EnsureClientCreated()
        {
            var authenticator = new Authenticator();
            var result        = await authenticator.AuthenticateAsync("MyFiles", ServiceIdentifierKind.Capability);

            // Create a client proxy:
            this.client = new SharePointClient(result.ServiceUri, result.GetAccessToken);
            this.client.Context.IgnoreMissingProperties = true;
        }
Example #17
0
        public async Task Test_AuthenticateAsync_SecondUnmatch_Fail()
        {
            var ret = await Authenticator.AuthenticateAsync("test", "1234");

            var ret2 = await Authenticator.AuthenticateAsync("test", "123");

            Assert.Equal("test", ret.Id);
            Assert.Null(ret2);
        }
Example #18
0
        public async Task Test_AuthenticateAsync_SecondMatch_Succeed()
        {
            var ret = await Authenticator.AuthenticateAsync("test", "1234");

            var ret2 = await Authenticator.AuthenticateAsync("test", "1234");

            Assert.Equal("test", ret.Id);
            Assert.Equal("test", ret2.Id);
        }
Example #19
0
        private async Task EnsureClientCreated()
        {
            var authenticator = new Authenticator();
            var result        = await authenticator.AuthenticateAsync("https://graph.windows.net/");

            this.userId = result.IdToken.UPN;

            // Create a client proxy:
            this.client = new AadGraphClient(new Uri("https://graph.windows.net/" + result.IdToken.TenantId), result.GetAccessToken);
        }
Example #20
0
        public async Task Authenticate_X509Identity()
        {
            var connectionManager = Mock.Of <IConnectionManager>();
            var clientCredentials = Mock.Of <IClientCredentials>(c =>
                                                                 c.Identity == Mock.Of <IModuleIdentity>(i => i.DeviceId == "my-device") &&
                                                                 c.AuthenticationType == AuthenticationType.X509Cert);

            var authenticator = new Authenticator(new TokenCredentialsAuthenticator(connectionManager, new NullCredentialsStore(), TestIotHub), "my-device");

            Assert.Equal(true, await authenticator.AuthenticateAsync(clientCredentials));
        }
Example #21
0
        public async Task Authenticate_NonNullIdentityTest()
        {
            var connectionManager        = Mock.Of <IConnectionManager>();
            var certificateAuthenticator = Mock.Of <IAuthenticator>();
            var credentialsCache         = Mock.Of <ICredentialsCache>();
            var clientCredentials        = Mock.Of <IClientCredentials>(c => c.Identity == Mock.Of <IModuleIdentity>(i => i.DeviceId == "my-device"));

            var authenticator = new Authenticator(new TokenCacheAuthenticator(new CloudTokenAuthenticator(connectionManager, TestIotHub), new NullCredentialsCache(), TestIotHub), certificateAuthenticator, credentialsCache);

            Assert.Equal(false, await authenticator.AuthenticateAsync(clientCredentials));
        }
Example #22
0
        public async Task ShouldBeAbleToAuthenticate()
        {
            //Arrange
            var info = CreateTestData <LoginInfo>();
            var user = CreateTestData <User>();

            Arrange(() => {
                user.Username = info.Username;

                hashProviderMock.Setup(x => x.ComputeHash(info.Password + user.Salt)).Returns(user.Password);
                var usersMock = MockAsyncQueryable(user);
                dbCtxMock.Setup(x => x.Users).Returns(usersMock.Object);
            });

            //Act
            var result = await target.AuthenticateAsync(info);

            //Assert
            Assert.Same(user, result);
        }
Example #23
0
        public async Task <ActionResult> RegisterAsync(RegistrationRequest registrationRequest, ModelStateDictionary modelState)
        {
            if (!modelState.IsValid)
            {
                return(BadRequestModelState(modelState));
            }

            if (registrationRequest.Password != registrationRequest.ConfirmPassword)
            {
                return(new BadRequestObjectResult(new ErrorResponse("Passwords don't match.")));
            }

            Account existingAccountByEmail = await _accountService.GetByEmailAsync(registrationRequest.Email);

            if (existingAccountByEmail != null)
            {
                return(new ConflictObjectResult(new ErrorResponse("Account with this email already exists.")));
            }

            Account existingAccountByUsername = await _accountService.GetByUsernameAsync(registrationRequest.Username);

            if (existingAccountByUsername != null)
            {
                return(new ConflictObjectResult(new ErrorResponse("Account with this username already exists.")));
            }

            string  passwordHash        = _passwordHasher.HashPassword(registrationRequest.Password);
            Account registrationAccount = new Account()
            {
                Email        = registrationRequest.Email,
                Username     = registrationRequest.Username,
                PasswordHash = passwordHash,
                DatesJoined  = DateTime.Today
            };

            Account account = await _accountService.CreateAsync(registrationAccount);

            AuthenticatedAccountResponse response = await _authenticator.AuthenticateAsync(account);

            return(new OkObjectResult(response));
        }
        public async Task<ExchangeClient> EnsureExchangeClient()
        {
            if (_exchangeClient != null)
                return _exchangeClient;

            var authenticator = new Authenticator();
            _authenticationInfo = await authenticator.AuthenticateAsync(ExchangeResourceId);

            _exchangeClient = new ExchangeClient(new Uri(ExchangeServiceRoot), _authenticationInfo.GetAccessToken);
            _isAuthenticated = true;
            return _exchangeClient;
        }
 public static async Task EnsureClientCreated(Context context) {
   
   Authenticator authenticator = new Authenticator(context);
   var authInfo = await authenticator.AuthenticateAsync(ExchangeResourceId);
   
   _strUserId = authInfo.IdToken.UPN;
   _exchangeClient = new ExchangeClient(new Uri(ExchangeServiceRoot), authInfo.GetAccessToken);
   
   var adAuthInfo = await authInfo.ReauthenticateAsync(AdServiceResourceId);
   _adClient = new AadGraphClient(new Uri("https://graph.windows.net/" + authInfo.IdToken.TenantId), 
                                  adAuthInfo.GetAccessToken);
 }
Example #26
0
        public async Task Authenticate_ConnectionManagerThrowsTest()
        {
            var cloudProxy        = Mock.Of <ICloudProxy>();
            var connectionManager = Mock.Of <IConnectionManager>();
            var clientCredentials = Mock.Of <IClientCredentials>(c => c.Identity == Mock.Of <IIdentity>());

            Mock.Get(connectionManager).Setup(cm => cm.CreateCloudConnectionAsync(clientCredentials)).ReturnsAsync(Try <ICloudProxy> .Failure(new ArgumentException()));
            Mock.Get(cloudProxy).Setup(cp => cp.IsActive).Returns(true);

            var authenticator = new Authenticator(new TokenCredentialsAuthenticator(connectionManager, new NullCredentialsStore(), TestIotHub), "your-device");

            Assert.Equal(false, await authenticator.AuthenticateAsync(clientCredentials));
        }
        public static async Task EnsureClientCreated(Context context)
        {
            Authenticator authenticator = new Authenticator(context);
            var           authInfo      = await authenticator.AuthenticateAsync(ExchangeResourceId);

            _strUserId      = authInfo.IdToken.UPN;
            _exchangeClient = new ExchangeClient(new Uri(ExchangeServiceRoot), authInfo.GetAccessToken);

            var adAuthInfo = await authInfo.ReauthenticateAsync(AdServiceResourceId);

            _adClient = new AadGraphClient(new Uri("https://graph.windows.net/" + authInfo.IdToken.TenantId),
                                           adAuthInfo.GetAccessToken);
        }
Example #28
0
        public async Task <ExchangeClient> EnsureExchangeClient()
        {
            if (_exchangeClient != null)
            {
                return(_exchangeClient);
            }

            var authenticator = new Authenticator();

            _authenticationInfo = await authenticator.AuthenticateAsync(ExchangeResourceId);

            _exchangeClient  = new ExchangeClient(new Uri(ExchangeServiceRoot), _authenticationInfo.GetAccessToken);
            _isAuthenticated = true;
            return(_exchangeClient);
        }
        async Task <RocketChatUserDto[]> GetUsersByEmailFromApiAsync(GetRocketChatUsersByEmailInputDto input)
        {
            // TODO: Create a proper filter query. For now it's easier to just fetch all users
            using (var client = HttpClientFactory.CreateClient("RocketChat"))
            {
                await Authenticator.AuthenticateAsync(client);

                var response = await client.GetFromJsonAsync <UserListResponse>("api/v1/users.list");

                return(response.Users
                       .Where(user => user.Emails != null &&
                              user.Emails.Any(email => input.Emails.Contains(email.Address, StringComparer.OrdinalIgnoreCase)))
                       .ToArray());
            }
        }
Example #30
0
        public async Task Authenticate_InactiveProxyTest()
        {
            var cloudProxy        = Mock.Of <ICloudProxy>();
            var connectionManager = Mock.Of <IConnectionManager>();
            var clientCredentials = Mock.Of <IClientCredentials>(c => c.Identity == Mock.Of <IIdentity>());

            Mock.Get(connectionManager).Setup(cm => cm.CreateCloudConnectionAsync(clientCredentials)).ReturnsAsync(Try.Success(cloudProxy));
            Mock.Get(connectionManager).Setup(cm => cm.AddDeviceConnection(It.IsAny <IClientCredentials>())).Returns(Task.CompletedTask);
            Mock.Get(cloudProxy).Setup(cp => cp.IsActive).Returns(false);

            var authenticator = new Authenticator(new TokenCacheAuthenticator(new CloudTokenAuthenticator(connectionManager), new NullCredentialsStore(), TestIotHub), "your-device", connectionManager);

            Assert.Equal(false, await authenticator.AuthenticateAsync(clientCredentials));
            Mock.Get(connectionManager).Verify(c => c.AddDeviceConnection(It.IsAny <IClientCredentials>()), Times.Never);
        }
        async Task <RocketChatUserDto> GetUserByEmailFromApiAsync(GetRocketChatUserByEmailInputDto input)
        {
            // To query data on the rocket chat API, we have to use the mongo-db query operators
            // See https://stackoverflow.com/questions/10700921/case-insensitive-search-with-in
            const string queryTemplate = "query={\"emails\":{\"$elemMatch\": {\"address\" : {\"$regex\":\"{0}\", \"$options\": \"i\"}}}}";

            using (var client = HttpClientFactory.CreateClient("RocketChat"))
            {
                await Authenticator.AuthenticateAsync(client);

                var queryParameter = string.Format(queryTemplate, input.Email);
                var response       = await client.GetFromJsonAsync <UserListResponse>($"api/v1/users.list?{queryParameter}");

                return(response.Users.FirstOrDefault());
            }
        }
Example #32
0
        public async Task Authenticate_ConnectionManagerThrowsTest()
        {
            var cloudProxy               = Mock.Of <ICloudProxy>();
            var connectionManager        = Mock.Of <IConnectionManager>();
            var certificateAuthenticator = Mock.Of <IAuthenticator>();
            var credentialsCache         = Mock.Of <ICredentialsCache>();
            var clientCredentials        = Mock.Of <IClientCredentials>(c => c.Identity == Mock.Of <IIdentity>());

            Mock.Get(connectionManager).Setup(cm => cm.CreateCloudConnectionAsync(clientCredentials)).ReturnsAsync(Try <ICloudProxy> .Failure(new ArgumentException()));
            Mock.Get(connectionManager).Setup(cm => cm.AddDeviceConnection(It.IsAny <IIdentity>(), It.IsAny <IDeviceProxy>())).Returns(Task.CompletedTask);
            Mock.Get(cloudProxy).Setup(cp => cp.IsActive).Returns(true);

            var authenticator = new Authenticator(new TokenCacheAuthenticator(new CloudTokenAuthenticator(connectionManager, TestIotHub), new NullCredentialsCache(), TestIotHub), certificateAuthenticator, credentialsCache);

            Assert.Equal(false, await authenticator.AuthenticateAsync(clientCredentials));
            Mock.Get(connectionManager).Verify(c => c.AddDeviceConnection(It.IsAny <IIdentity>(), It.IsAny <IDeviceProxy>()), Times.Never);
        }
Example #33
0
        public async Task AuthenticateTest()
        {
            var cloudProxy               = Mock.Of <ICloudProxy>();
            var connectionManager        = Mock.Of <IConnectionManager>();
            var certificateAuthenticator = Mock.Of <IAuthenticator>();
            var credentialsCache         = Mock.Of <ICredentialsCache>();
            var clientCredentials        = Mock.Of <ITokenCredentials>(c => c.Identity == Mock.Of <IIdentity>());

            Mock.Get(connectionManager).Setup(cm => cm.CreateCloudConnectionAsync(clientCredentials)).ReturnsAsync(Try.Success(cloudProxy));
            Mock.Get(connectionManager).Setup(cm => cm.AddDeviceConnection(It.IsAny <IIdentity>(), It.IsAny <IDeviceProxy>())).Returns(Task.CompletedTask);
            Mock.Get(cloudProxy).Setup(cp => cp.IsActive).Returns(true);

            var authenticator = new Authenticator(new TokenCacheAuthenticator(new CloudTokenAuthenticator(connectionManager, TestIotHub), new NullCredentialsCache(), TestIotHub), certificateAuthenticator, "your-device", credentialsCache);

            Assert.Equal(true, await authenticator.AuthenticateAsync(clientCredentials));
            Mock.Get(connectionManager).Verify();
        }
Example #34
0
        public async Task Authenticate_X509Identity()
        {
            var connectionManager        = Mock.Of <IConnectionManager>();
            var credentialsCache         = Mock.Of <ICredentialsCache>();
            var certificateAuthenticator = Mock.Of <IAuthenticator>();
            var clientCredentials        = Mock.Of <ICertificateCredentials>(c =>
                                                                             c.Identity == Mock.Of <IModuleIdentity>(i => i.DeviceId == "my-device") &&
                                                                             c.AuthenticationType == AuthenticationType.X509Cert);
            var tokenAuthenticator = Mock.Of <IAuthenticator>();

            Mock.Get(credentialsCache).Setup(cc => cc.Add(clientCredentials)).Returns(Task.CompletedTask);
            Mock.Get(certificateAuthenticator).Setup(ca => ca.AuthenticateAsync(clientCredentials)).ReturnsAsync(true);
            var authenticator = new Authenticator(tokenAuthenticator, certificateAuthenticator, "my-device", credentialsCache);

            Assert.Equal(true, await authenticator.AuthenticateAsync(clientCredentials));
            Mock.Get(credentialsCache).Verify(cc => cc.Add(clientCredentials));
        }
        public async Task SendMessage(MessageDto message)
        {
            using (var client = HttpClientFactory.CreateClient("RocketChat"))
            {
                await Authenticator.AuthenticateAsync(client);

                var payload  = JsonSerializer.Serialize(message);
                var content  = new StringContent(payload, Encoding.UTF8, "application/json");
                var response = await client.PostAsync("api/v1/chat.postMessage", content);

                if (!response.IsSuccessStatusCode)
                {
                    var contentMessage = await response.Content.ReadAsStringAsync();

                    throw new InvalidOperationException(contentMessage);
                }
            }
        }
Example #36
0
        public Task StartAsync(CancellationToken providedCancellationToken)
        {
            if (providedCancellationToken.CanBeCanceled)
            {
                providedCancellationToken.Register(() => _cancellationTokenSource.Cancel());
            }
            var cancellationToken = _cancellationTokenSource.Token;

            Task.Run(async() =>
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    int delay;
                    try
                    {
                        if (!_authenticationDone)
                        {
                            _logger.LogInformation("Attempting to authenticate the session");
                            var credentials     = await _localCredentialsProvider.GetCredentialsAsync <UsernamePasswordCredentialsViewModel>("CoreConnectionCredentials");
                            delay               = Convert.ToInt32(await _authenticator.AuthenticateAsync(credentials.Username, credentials.Password));
                            _authenticationDone = true;
                        }
                        else
                        {
                            _logger.LogInformation("Attempting to refresh the session");
                            delay = Convert.ToInt32(await _authenticator.RefreshAsync());
                        }
                        _logger.LogDebug("Successful. Refreshing in {0} seconds", delay);
                    }
                    catch (HttpRequestException ex)
                    {
                        delay = 10;
                        _logger.LogError("Failed to authenticate. Retrying in {0} seconds", delay);
                    }

                    await Task.Delay(delay * 1000, cancellationToken);
                }
            }, cancellationToken);

            return(Task.CompletedTask);
        }
        private async Task <bool> ForwardMessage(string messageID, string recipientName, string recipientAddress, string forwardMessage)
        {
            //get authorization token
            Authenticator authenticator = new Authenticator();
            var           authInfo      = await authenticator.AuthenticateAsync(ExchangeResourceId);

            //send request through HttpClient
            HttpClient httpClient = new HttpClient();

            httpClient.BaseAddress = new Uri(ExchangeResourceId);

            //add authorization header
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await authInfo.GetAccessToken());

            ForwardMessage forwardContent = new Models.ForwardMessage();

            forwardContent.Comment = forwardMessage;
            forwardContent.ToRecipients.Add(new Recipient()
            {
                Address = recipientAddress, Name = recipientName
            });

            StringContent postContent = new StringContent(JsonConvert.SerializeObject(forwardContent));

            postContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            //send request
            var response = httpClient.PostAsync("/ews/odata/Me/Inbox/Messages('" + messageID + "')/Forward", postContent).Result;

            if (response.StatusCode == HttpStatusCode.OK || response.StatusCode == HttpStatusCode.Accepted)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
 public static async Task EnsureClientCreated(Context context) {
   Authenticator authenticator = new Authenticator(context);
   var authInfo = await authenticator.AuthenticateAsync(ExchangeResourceId);
   userId = authInfo.IdToken.UPN;
   exchangeClient = new ExchangeClient(new Uri(ExchangeServiceRoot), authInfo.GetAccessToken);
 }