IdentityServer 4:客户端的无效授予类型:authorization_code

时间:2020-04-23 10:36:54

标签: angular asp.net-core identityserver4

我正在尝试使用身份服务器授权我的角度客户端。以下是我的角度客户端的设置。

  authority: 'http://localhost:5000',
  client_id: 'clientid',
  redirect_uri: 'https://localhost:44384/auth-callback',
  post_logout_redirect_uri: 'https://localhost:44384/',
  response_type: "code",
  scope: "openid profile",
  filterProtocolClaims: true,
  loadUserInfo: true,
  automaticSilentRenew: true,
  silent_redirect_uri: 'http://localhost:44384/silent-refresh.html'

类似的客户端在IdentityServer端注册。

 new Client
 {
     ClientId = "clientid",     
     AllowedScopes = { "openid", "profile" },
     AllowedGrantTypes = GrantTypes.Code,
     RequirePkce = true,
     RequireClientSecret = false,
     AllowAccessTokensViaBrowser = true,
     AllowOfflineAccess = false,
     AccessTokenLifetime = 3600,
     RedirectUris={"https://localhost:44384/auth-callback" },
     PostLogoutRedirectUris=  {"https://localhost:44384/" },
     RequireConsent= false
  }

,它工作正常。但是当我将相同的客户端设置移至数据库时,它给了我客户端无效的授予类型

以下是VS日志

[15:15:56 Debug] IdentityServer4.EntityFramework.Stores.ClientStore
clientid found in database: True

[15:15:56 Debug] IdentityServer4.Stores.ValidatingClientStore
client configuration validation for client clientid succeeded.

[15:15:56 Debug] IdentityServer4.Validation.AuthorizeRequestValidator
Checking for PKCE parameters

[15:15:56 Error] IdentityServer4.Validation.AuthorizeRequestValidator: Invalid grant type for client: authorization_code

客户端的数据库数据如下。

enter image description here

和GrantType。

enter image description here

1 个答案:

答案 0 :(得分:3)

我已经解决了这个问题。我在服务器端用于注册的GrantType错误。

从内存中获取客户端时,我正在编写以下代码。即来自appsettings.json文件

 new Client
 {
     -------
     -------
     AllowedGrantTypes = GrantTypes.Code,
     --------
     --------
}

后来我从数据库中获取客户信息,并使用相同的grantTypeCode,这是错误的。它的定义应类似于authorization_code

因此,通过将数据库中的GrantTypeCode更改为authorization_code。解决了我的问题。