【问题标题】:Authorization Code with Proof Key token request results in invalid client response带有证明密钥令牌请求的授权代码导致无效的客户端响应
【发布时间】:2018-04-17 20:33:29
【问题描述】:

我目前正在评估 AppAuth (https://appauth.io/) 以用于本机移动应用程序以及当前使用 IdentityServer3 的 STS。我已经像这样配置了一个客户端:

new IdentityServer3.Core.Models.Client
{
    Enabled = true,
    ClientId = "app",
    ClientName = "app",
    ClientUri = "app:/",
    Flow = Flows.AuthorizationCodeWithProofKey,
    RequireConsent = false,
    RequireSignOutPrompt = false,
    SlidingRefreshTokenLifetime = 28800,
    AllowAccessTokensViaBrowser = true,

    RedirectUris = new List<string>
    {
        "app:/signin"
    },
    PostLogoutRedirectUris = new List<string>
    {
        "app:/signout"
    },
    AllowedScopes = new List<string>
    {
                StandardScopes.OpenId.Name.Name,
                StandardScopes.Email.Name.Name,
                StandardScopes.Profile.Name.Name,
                StandardScopes.Roles.Name.Name,
                StandardScopes.OfflineAccess.Name,
    }
}

初始授权请求成功,IdentityServer3 返回授权码。现在我尝试了随后的令牌请求,这导致 HTTP 400 带有一个 invalid_client 错误以及 IdentityServer3 日志中的以下消息:

2018-04-17 10:16:38.324 +02:00 [Information] Start token request
2018-04-17 10:16:38.324 +02:00 [Debug] Start client validation
2018-04-17 10:16:38.324 +02:00 [Debug] Start parsing Basic Authentication secret
2018-04-17 10:16:38.324 +02:00 [Debug] Start parsing for secret in post body
2018-04-17 10:16:38.324 +02:00 [Debug] No secret in post body found
2018-04-17 10:16:38.324 +02:00 [Debug] Start parsing for X.509 certificate
2018-04-17 10:16:38.324 +02:00 [Debug] X.509 certificate not found.
2018-04-17 10:16:38.324 +02:00 [Information] Parser found no secret
2018-04-17 10:16:38.324 +02:00 [Information] No client secret found
2018-04-17 10:16:38.324 +02:00 [Information] End token request
2018-04-17 10:16:38.324 +02:00 [Information] Returning error: invalid_client

我是否理解有误,或者为什么 IdentityServer3 不返回访问令牌?

【问题讨论】:

  • 你在授权请求中设置了code_challenge,在令牌请求中设置了code_verifier吗?
  • 是的。我在返回授权码的授权请求中设置了code_challenge。我还在令牌请求中设置了code_verifier,导致客户端响应无效。
  • 我刚刚尝试了@Kahbazi 的建议。在 IdSrv3 中的客户端配置中添加客户端密码并在令牌请求中另外设置授权标头后,我得到一个 id 和访问令牌。
  • 是的,但奇怪的是,您需要为此流程提供客户端密码。请参阅:github.com/IdentityModel/IdentityModel.OidcClient/issues/25

标签: oauth openid identityserver3 appauth


【解决方案1】:

您需要在Authorization Code 流的令牌请求中验证Client。所以你需要为你的客户设置ClientSecrets

new IdentityServer3.Core.Models.Client
{
    /// your properties

    ClientSecrets = new List<Secret>
    {
        new Secret("secret".Sha256())
    }
}

您需要在令牌请求中将client_secret 作为查询字符串发送。

或者您可以使用BasicAuthentication。在这种情况下,您需要在身份验证标头中添加Base64(ClientId:ClientSecret)

【讨论】:

  • 我刚试过这个,它似乎工作。我不明白为什么需要客户端密码? PKCE 用于公共客户端,其中客户端密钥无论如何都没有意义。
猜你喜欢
  • 1970-01-01
  • 2020-09-03
  • 2020-01-24
  • 1970-01-01
  • 2017-08-28
  • 2021-01-02
  • 1970-01-01
  • 2019-12-24
  • 2019-12-25
相关资源
最近更新 更多