public async Task AuthenticateAsync_AuthenticateWithoutDiscoveryService( IAuthenticationResult authenticationResult, MockAuthenticationContextWrapper.AuthenticationResultCallback authenticationResultCallback, MockAuthenticationContextWrapper.AuthenticationResultSilentCallback authenticationResultSilentCallback, MockAuthenticationContextWrapper.AuthenticationResultByRefreshTokenCallback authenticationResultByRefreshTokenCallback) { this.serviceInfo.BaseUrl = "https://localhost"; this.serviceInfo.ServiceResource = "https://resource/"; this.authenticationProvider.authenticationContextWrapper = new MockAuthenticationContextWrapper { AcquireTokenAsyncCallback = authenticationResultCallback, AcquireTokenSilentAsyncCallback = authenticationResultSilentCallback, AcquireTokenByRefreshTokenAsyncCallback = authenticationResultByRefreshTokenCallback, }; var accountSession = await this.authenticationProvider.AuthenticateAsync(); Assert.AreEqual(authenticationResult.AccessToken, accountSession.AccessToken, "Unexpected access token set."); Assert.AreEqual(authenticationResult.AccessTokenType, accountSession.AccessTokenType, "Unexpected access token type set."); Assert.AreEqual(AccountType.ActiveDirectory, accountSession.AccountType, "Unexpected account type set."); Assert.IsTrue(accountSession.CanSignOut, "CanSignOut set to false."); Assert.AreEqual(this.serviceInfo.AppId, accountSession.ClientId, "Unexpected client ID set."); Assert.AreEqual(authenticationResult.ExpiresOn, accountSession.ExpiresOnUtc, "Unexpected expiration set."); Assert.IsNull(accountSession.UserId, "Unexpected user ID set."); }
public async Task <AccountSession> AuthenticateWithDiscoveryService( MockAuthenticationContextWrapper.AuthenticationResultCallback authenticationResultCallback, MockAuthenticationContextWrapper.AuthenticationResultSilentCallback authenticationResultSilentCallback, DiscoveryServiceResponse discoveryServiceResponse = null) { const string serviceEndpointUri = "https://localhost"; const string serviceResourceId = "https://localhost/resource/"; if (discoveryServiceResponse == null) { discoveryServiceResponse = new DiscoveryServiceResponse { Value = new List <DiscoveryService> { new DiscoveryService { Capability = Constants.Authentication.MyFilesCapability, ServiceApiVersion = this.serviceInfo.OneDriveServiceEndpointVersion, ServiceEndpointUri = serviceEndpointUri, ServiceResourceId = serviceResourceId, } } }; } var requestBodyString = this.serializer.SerializeObject(discoveryServiceResponse); AccountSession accountSession; using (var stringContent = new StringContent(requestBodyString)) { this.httpResponseMessage.Content = stringContent; this.authenticationProvider.authenticationContextWrapper = new MockAuthenticationContextWrapper { AcquireTokenAsyncCallback = authenticationResultCallback, AcquireTokenSilentAsyncCallback = authenticationResultSilentCallback, }; accountSession = await this.authenticationProvider.AuthenticateAsync(); } return(accountSession); }
public async Task AuthenticateAsync_AuthenticateWithDiscoveryService( IAuthenticationResult authenticationResult, MockAuthenticationContextWrapper.AuthenticationResultCallback authenticationResultCallback, MockAuthenticationContextWrapper.AuthenticationResultSilentCallback authenticationResultSilentCallback) { const string serviceEndpointUri = "https://localhost"; const string serviceResourceId = "https://localhost/resource/"; var discoveryServiceResponse = new DiscoveryServiceResponse { Value = new List <DiscoveryService> { new DiscoveryService { Capability = Constants.Authentication.MyFilesCapability, ServiceApiVersion = this.serviceInfo.OneDriveServiceEndpointVersion, ServiceEndpointUri = serviceEndpointUri, ServiceResourceId = serviceResourceId, } } }; var accountSession = await this.AuthenticateWithDiscoveryService( authenticationResultCallback, authenticationResultSilentCallback); Assert.AreEqual(serviceEndpointUri, this.serviceInfo.BaseUrl, "Base URL not set."); Assert.AreEqual(serviceResourceId, this.serviceInfo.ServiceResource, "Service resource not set."); Assert.AreEqual(authenticationResult.AccessToken, accountSession.AccessToken, "Unexpected access token set."); Assert.AreEqual(authenticationResult.AccessTokenType, accountSession.AccessTokenType, "Unexpected access token type set."); Assert.AreEqual(AccountType.ActiveDirectory, accountSession.AccountType, "Unexpected account type set."); Assert.IsTrue(accountSession.CanSignOut, "CanSignOut set to false."); Assert.AreEqual(this.serviceInfo.AppId, accountSession.ClientId, "Unexpected client ID set."); Assert.AreEqual(authenticationResult.ExpiresOn, accountSession.ExpiresOnUtc, "Unexpected expiration set."); Assert.IsNull(accountSession.UserId, "Unexpected user ID set."); }