【问题标题】:Identity Server connect/token unsupported grant_type error身份服务器连接/令牌不支持 grant_type 错误
【发布时间】:2022-01-03 23:02:59
【问题描述】:

我使用 .net core 3.1 创建了一个身份服务器,但是当我尝试获取令牌时出现此错误。

这是我的 appsettings.json 文件

"Clients": [
  {
    "ClientId": "portal-api",
    "AlwaysIncludeUserClaimsInIdToken": true,
    "AllowOfflineAccess": true, //support refresh tokens
    "AccessTokenLifetime": 3600,
    "RequireConsent": false,
    "ClientSecrets": [ { "Value": "lxl76J788Cvf1ds8CQJuFYGwTi7e3BXGCRK2JIUekmk=" } ],
    "AllowedGrantTypes": [ "password", "code" ],
    "AllowedScopes": [ "rest.auth" ],
    "RefreshTokenUsage": "OneTimeOnly",
    "RequireClientSecret": true,
    "Enabled": true
  }
]

},

【问题讨论】:

  • 您能发布您如何在 Startup.cs 中配置 IdentityServer 吗?您确定这些设置实际上是从 appsettings 应用的吗?

标签: asp.net-core identityserver4


【解决方案1】:

如果您查看here,您会发现 appsettings 应该以 IdentityServer 对象开头,例如:

"IdentityServer": {
    "IssuerUri": "urn:sso.company.com",
    "Clients": [
        {
            "Enabled": true,
            "ClientId": "local-dev",
            "ClientName": "Local Development",
            "ClientSecrets": [ { "Value": "<Insert Sha256 hash of the secret encoded as Base64 string>" } ],
            "AllowedGrantTypes": [ "client_credentials" ],
            "AllowedScopes": [ "api1" ],
        }
    ]
}

【讨论】:

    【解决方案2】:

    与您的问题没有直接关系,但使用密码授予违反了当前的最佳做法,有关详细信息,请参阅https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics-18#section-2.4

    我还建议不要为单个客户端允许多种授权类型,因为这会扩大可能的攻击媒介。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-28
      • 2013-12-24
      • 2020-07-26
      • 1970-01-01
      • 1970-01-01
      • 2017-11-14
      • 2018-04-03
      相关资源
      最近更新 更多