IdentityServer4 {"error": "invalid_client"} - PullRequest
0 голосов
/ 12 апреля 2020

Я использую IdentityServer4 (версия 3.0.2.0) и сталкиваюсь с без идентификатора клиента . Точная ошибка:

ОШИБКА | Клиент с идентификатором myclientId не найден. прерывание

Startup.cs проекта IdentityServer4

 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
                });

Кроме того, у меня есть sha256, преобразованный client_secret в appsettings. json файл, примерный 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: порт / 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 голосов
/ 18 апреля 2020

Я отправляю ответ на свой вопрос, потому что я решил проблему. Для меня ниже данное поле было проблемой. После удаления этого поля код работал нормально.

"RefreshTokenExpiration": true

Оказывается, IdentityServer4.Models.Client не имеет никакого логического поля с именем RefreshTokenExpiration , но объект класса.

...