protected async Task <string> GetToken(string grantType) { var tokenResponse = await _identityServerProxy .GetTokenAsync( _clientConf, grantType, new Dictionary <string, string>()); return(tokenResponse.AccessToken); }
public async Task IdentityServerProxy_GetTokenAsync_Extension_Grant_Valid_User_Succeeds() { var clientConfiguration = new ClientConfiguration("MyClient", "MySecret"); var client = new Client { ClientId = clientConfiguration.Id, ClientSecrets = new List <Secret> { new Secret(clientConfiguration.Secret.Sha256()) }, AllowedScopes = new[] { "api1", IdentityServerConstants.StandardScopes.OfflineAccess, IdentityServerConstants.StandardScopes.OpenId, IdentityServerConstants.StandardScopes.Profile }, AllowedGrantTypes = new[] { "Custom" }, AccessTokenType = AccessTokenType.Jwt, AccessTokenLifetime = 7200, AllowOfflineAccess = true }; var webHostBuilder = new IdentityServerTestWebHostBuilder() .AddClients(client) .AddApiResources(new ApiResource("api1", "api1name")) .AddApiScopes(new ApiScope("api1")) .AddIdentityResources(new IdentityResources.OpenId(), new IdentityResources.Profile()) .UseServices((context, collection) => collection.AddScoped <IExtensionGrantValidator, ExtensionsGrantValidator>()) .CreateWebHostBuider(); var identityServerProxy = new IdentityServerWebHostProxy(webHostBuilder); var scopes = new[] { "api1", "offline_access", "openid", "profile" }; var tokenResponse = await identityServerProxy.GetTokenAsync(clientConfiguration, "Custom", new Dictionary <string, string> { { "scope", string.Join(" ", scopes) }, { "username", "user" }, { "password", "password" } }); Assert.NotNull(tokenResponse); Assert.False(tokenResponse.IsError, tokenResponse.Error ?? tokenResponse.ErrorDescription); Assert.Equal(7200, tokenResponse.ExpiresIn); Assert.NotNull(tokenResponse.AccessToken); Assert.NotNull(tokenResponse.RefreshToken); }