【问题标题】:IdentityServer 4: Invalid grant type for client: authorization_codeIdentityServer 4:客户端的授权类型无效:authorization_code
【发布时间】:2020-08-06 15:42:30
【问题描述】:

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

  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
  }

它工作正常。但是当我将相同的客户端设置移动到数据库时,它给了我 Invalid grant type for client

以下是 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

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

对于grantType。

【问题讨论】:

  • 您能分享一下您的数据库中的内容吗?
  • @mackie 问题已更新

标签: angular asp.net-core identityserver4


【解决方案1】:

我想通了。我在数据库中提到的GrantType是错误的。

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

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

后来当我将此信息移至数据库时,我错误地使用了相同的grantType,即Code,这是错误的。它应该被定义为authorization_code

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-02
    • 2019-01-24
    • 2019-11-25
    • 2015-01-08
    • 2023-04-03
    • 2020-06-17
    相关资源
    最近更新 更多