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 void ClientCredentialsHttpClient_HttpClientOptionsType_ShouldBeCorrect() { var httpClient = new ClientCredentialsHttpClient( IHttpClientFactoryMocks.Get( HttpStatusCode.OK, TokenResponseObjects.GetValidTokenResponseString("access_token", 10) ).CreateClient("test") ); Assert.AreEqual(typeof(ClientCredentialsOptions), httpClient.HttpClientOptionsType); }
public async Task ClientCredentialsHttpClient_GetTokenResponseAsync_ShouldReturnAccessToken() { var httpClient = new ClientCredentialsHttpClient( IHttpClientFactoryMocks.Get( HttpStatusCode.OK, TokenResponseObjects.GetValidTokenResponseString("access_token", 10) ).CreateClient("test") ); var clientCredentialOptions = new ClientCredentialsOptions { Address = "http://localhost/" + Guid.NewGuid(), ClientId = "ClientId", ClientSecret = "secret", Scope = "scope" }; var tokenResponse = await httpClient.GetTokenResponseAsync(clientCredentialOptions); Assert.AreEqual(HttpStatusCode.OK, tokenResponse.HttpStatusCode); Assert.AreEqual("access_token", tokenResponse.AccessToken); }