【问题标题】:Resource owner password credential grant type not supported不支持资源所有者密码凭据授予类型
【发布时间】:2017-12-30 17:44:09
【问题描述】:

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

我是这样配置身份服务器的:

  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***"
        }
      }

我想念什么?

【问题讨论】:

  • 您是如何实际配置 IdSrv 的? (在启动中)
  • 您是否提供了自定义 IResourceOwnerPasswordValidator?没有那个身份服务器就不知道如何实际验证密码是否正确。
  • 我更新了我的帖子
  • AFAIK,您需要添加测试用户、身份或自定义用户存储。目前,您尚未为用户配置任何内容
  • Like@Evk 建议,添加一个 IResourceOwnerPasswordValidator。它甚至在错误消息“配置 IResourceOwnerPasswordValidator”中字面上都说

标签: c# angular identityserver4


【解决方案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>();

【讨论】:

  • 嘿,是的,这真的救了我的培根,感谢您的更新。老实说,不知道他们之前是如何让它工作的,哈哈。
猜你喜欢
  • 2019-12-08
  • 2014-07-25
  • 1970-01-01
  • 2018-05-25
  • 2016-12-31
  • 2016-07-19
  • 2014-09-02
  • 2021-12-05
  • 2017-08-27
相关资源
最近更新 更多