IdentityServer4 {“错误”:“ invalid_client”}

时间:2020-04-12 13:15:31

标签: authentication asp.net-core identityserver4

我正在使用IdentityServer4(版本3.0.2.0),并且遇到没有客户端ID 的问题。确切的错误是

错误|找不到ID为“ myclientId”的客户端。终止

IdentityServer4项目的Startup.cs

 services.AddIdentityServer()
                .AddDeveloperSigningCredential()
               // .AddInMemoryCaching()
                .AddInMemoryApiResources(Configuration.GetSection("IdentityServer:ApiResources"))
                .AddInMemoryClients(Configuration.GetSection("IdentityServer:Clients"))
                .AddOperationalStore(options =>
                {
                    options.ConfigureDbContext = builder =>
                        builder.UseSqlServer(connectionString,
                            sql => sql.MigrationsAssembly(migrationsAssembly));

                    // this enables automatic token cleanup. this is optional.
                    options.EnableTokenCleanup = Convert.ToBoolean(Configuration["CleanUp:IsEnabled"]);
                    options.TokenCleanupInterval = Convert.ToInt32(Configuration["CleanUp:Interval"]); // interval in seconds
                });

此外,我在appsettings.json文件中有sha256转换后的client_secret,示例appsettings.json

    "IdentityServer": {
     "ApiResources": [
      {
        "Name": "myapi",
        "DisplayName": "my api",
        "Scopes": [
          {
            "Name": "mycustomscope"
          },
          {
            "Name": "openid"
          }
        ],
        "ApiSecrets": [
          {
            "Value": "my sha256 converted secret string",
            "Description": "my api"
          }
        ]
      }
    ],
    "Clients": [

      {
        "Enabled": true,
        "ClientId": "myclientId",
        "AccessTokenLifetime": 100000000,
        "ProtocolType": "oidc",
        "RequireClientSecret": true,
        "IdentityTokenLifetime": 300,
        "AuthorizationCodeLifetime": 300,
        "ConsentLifetime": 300,
        "AbsoluteRefreshTokenLifetime": 2592000,
        "SlidingRefreshTokenLifetime": 1296000,
        "RefreshTokenExpiration": true,
        "AlwaysSendClientClaims": false,
        "ClientName": "myclientId",
        "ClientSecrets": [
          {
            "Value": "my sha256 converted secret string",
            "Type": "SharedSecret"
          }
        ],
        "AllowedGrantTypes": [ "client_credentials", "password" ],
        "AllowedScopes": [ "mycustomscope", "openid" ],
        "RequireConsent": true
      }
    ]

}

邮递员/ JMeter的示例令牌请求

URL: https://myip:port/myappPool/connect/token

方法类型: POST

参数为:

    { 
      "client_id":"myclientId",
      "client_secret": "plaintext secret",
      "username":"abcdefghijkl",
      "scope":"mycustomscope",
      "device_id":"custom property",
      "password": "mypassword",
      "grant_type":"password",
      "app_version":"custom property",
      "hashed_value":"custom property"
    }

1 个答案:

答案 0 :(得分:0)

因为我已经解决了该问题,所以我正在发布对自己问题的答案。对于我来说,下面的给定字段造成了问题。 删除此字段后,代码运行正常。

"RefreshTokenExpiration": true

结果是,IdentityServer4.Models.Client没有名为 RefreshTokenExpiration 的任何布尔字段,而是类对象。