不支持资源所有者密码凭据授予类型

时间:2017-12-30 17:44:09

标签: c# angular identityserver4

我在Identity Server 4应用程序中使用Angular 5

我以这种方式配置了Identity Server:

  public static IEnumerable<Client> GetClients()
        {
            return new List<Client>
            {
                new Client
                {
                    ClientId = "client",
                    AllowedGrantTypes = GrantTypes.ResourceOwnerPassword, 
                    AllowAccessTokensViaBrowser = true,
                    RequireClientSecret = false, 

                    AllowedScopes = {
                        "api1"
                    },

                    AllowedCorsOrigins = new List<string>
                    {
                        "http://localhost:4200"
                    } 
                }
            };
        }


    public void ConfigureServices(IServiceCollection services)
    {

        var cors = new DefaultCorsPolicyService(_loggerFactory.CreateLogger<DefaultCorsPolicyService>())
        {
            AllowedOrigins = { "http://localhost:4200" }
        };
        services.AddSingleton<ICorsPolicyService>(cors);

        services.AddIdentityServer()
                .AddDeveloperSigningCredential()
                .AddInMemoryApiResources(Config.GetApiResources())
                .AddInMemoryClients(Config.GetClients());
    }

这是我的Angular配置:

export const oAuthDevelopmentConfig: AuthConfig = {

    clientId: "client",
    scope: "api1",
    oidc: false,
    issuer: "http://localhost:5000",
    requireHttps: false
}

我用这种方式配置:

...
    signin(): void {
        this.oAuthService
            .fetchTokenUsingPasswordFlowAndLoadUserProfile(this.model.username, this.model.password)
            .then(() => {
                this.authenticationService.init();
...

当我尝试访问服务器时,收到以下错误,但我无法理解问题所在:

info: IdentityServer4.Hosting.IdentityServerMiddleware[0]
      Invoking IdentityServer endpoint: IdentityServer4.Endpoints.TokenEndpoint for /connect/token
info: IdentityServer4.Validation.NotSupportedResourceOwnerPasswordValidator[0]
      Resource owner password credential type not supported. Configure an IResourceOwnerPasswordValidator.
fail: IdentityServer4.Validation.TokenRequestValidator[0]
      Resource owner password credential grant type not supported
fail: IdentityServer4.Validation.TokenRequestValidator[0]
      {
        "ClientId": "client",
        "GrantType": "password",
        "Scopes": "api1",
        "UserName": "admin@gmail.com",
        "Raw": {
          "grant_type": "password",
          "client_id": "client",
          "scope": "api1",
          "username": "admin@gmail.com",
          "password": "***REDACTED***"
        }
      }

我想念的是什么?

1 个答案:

答案 0 :(得分:1)

这是一个古老的问题,但是今天我在同一个问题上做了一些努力。 我发现了这种方法: AddResourceOwnerValidator 。提出此问题时,可能不存在此方法。

这是我的AddIdentityServer配置。

        services.AddIdentityServer(opt => opt.IssuerUri = issuerUri)
            .AddDeveloperSigningCredential()
            .AddInMemoryApiResources(IdServer.Configuration.GetApiResources())
            .AddInMemoryClients(IdServer.Configuration.GetClients())
            .AddProfileService<ProfileService>()
            .AddResourceOwnerValidator<ResourceOwnerPasswordValidator>()
            ;

在提出原始问题时,答案可能是这样的,如问题IdentityServer4 register UserService and get users from database in asp.net core

所示
//Inject the classes we just created
services.AddTransient<IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();
services.AddTransient<IProfileService, ProfileService>();