public async Task IdentityServerService_GetTokenResponse_ShouldReturnAccessToken() { var identityServerService = new IdentityServerService( new IdentityServerHttpClientSelector( new List <IIdentityServerHttpClient> { { new ClientCredentialsHttpClient( IHttpClientFactoryMocks.Get( HttpStatusCode.OK, TokenResponseObjects.GetValidTokenResponseString("live_access_token", 10) ).CreateClient("test") ) } } ), new TokenResponseCacheManager( new MemoryCache( Options.Create(new MemoryCacheOptions()) ) ) ); var tokenServiceOptions = new ClientCredentialsOptions { Address = "http://localhost/" + Guid.NewGuid(), ClientId = "ClientId", ClientSecret = "secret", Scope = "scope" }; var accessToken = await identityServerService.GetTokenResponseAsync(tokenServiceOptions); Assert.AreEqual("live_access_token", accessToken.AccessToken); }
public async Task IdentityServerHttpClientSelector_Get_ShouldSelectPassword() { var identityServerService = new IdentityServerService( new IdentityServerHttpClientSelector( new List <IIdentityServerHttpClient> { { new ClientCredentialsHttpClient( IHttpClientFactoryMocks.Get(HttpStatusCode.OK, "{\"access_token\": \"client_credentials_access_token\"}").CreateClient("test") ) }, { new PasswordHttpClient( IHttpClientFactoryMocks.Get(HttpStatusCode.OK, "{\"access_token\": \"password_access_token\"}").CreateClient("test") ) } } ), new TokenResponseCacheManager( new MemoryCache( Options.Create(new MemoryCacheOptions()) ) ) ); var tokenServiceOptions = new PasswordOptions { Address = "http://localhost/" + Guid.NewGuid(), ClientId = "ClientId", ClientSecret = "secret", Scope = "scope", Username = "******", Password = "******" }; var accessToken = await identityServerService.GetTokenResponseAsync(tokenServiceOptions); Assert.AreEqual("password_access_token", accessToken.AccessToken); }
public Service(IdentityService identityService, IdentityServerService identityServerService) { _identityService = identityService; _identityServerService = identityServerService; }