【问题标题】:Refresh token with Keycloak使用 Keycloak 刷新令牌
【发布时间】:2019-04-21 16:25:23
【问题描述】:

我在 [Keycloak][2] 中使用 [JWT 进行客户端身份验证][1]:

 POST /token.oauth2 HTTP/1.1
 Host: as.example.com
 Content-Type: application/x-www-form-urlencoded

 grant_type=authorization_code&
 code=vAZEIHjQTHuGgaSvyW9hO0RpusLzkvTOww3trZBxZpo&
 client_assertion_type=urn%3Aietf%3Aparams%3Aoauth%3A
 client-assertion-type%3Ajwt-bearer&
 client_assertion=eyJhbGciOiJSUzI1NiJ9.
 eyJpc3Mi[...omitted for brevity...].
 cC4hiUPo[...omitted for brevity...]

我明白了:

assess_token
refresh_token
token_type
expires_in

当我尝试刷新令牌时,我自己发送refresh_token,授予类型refresh_token 并获取:

    "error": "unauthorized_client",
    "error_description": "INVALID_CREDENTIALS: Invalid client credentials"
}```

when I specify `client_id` I get:

```{
    "error": "invalid_client",
    "error_description": "Parameter client_assertion_type is missing"
}```

If I specify `client_assertion_type` I get error that `client_assertion` itself is missing, so I literally have to provide parameters I provided when retrieved access token.

How that refreshing process actually should work?


  [1]: https://datatracker.ietf.org/doc/html/draft-ietf-oauth-jwt-bearer-12#section-2.2
  [2]: https://www.keycloak.org

【问题讨论】:

    标签: oauth-2.0 openid openid-connect keycloak


    【解决方案1】:

    这很可能是 Keycloak 定义的限制或策略。 RFC7523(用于客户端身份验证的 JWT)确实允许在存在 JWT 身份验证时启用客户端凭据。这是从3.1. Authorization Grant Processing 突出显示的

    JWT 授权授权可以在有或没有客户端的情况下使用 身份验证或识别。无论客户端 身份验证需要与 JWT 授权结合使用 授权以及支持的客户端身份验证类型是 授权服务器自行决定的策略决定。 但是,如果请求中存在客户端凭据,则 授权服务器必须验证它们。

    因此,即使Keycloak support JWT client authentication,它仍可能需要客户端凭据出现在刷新令牌请求中。但是,这可能是他们最终的限制。

    此外,令牌刷新是通过RFC6749 - The OAuth 2.0 Authorization Framework 定义的。根据它的section 6,当客户端是机密客户端(只是使用 id 和密码创建的客户端)时,刷新令牌请求必须包含客户端凭据。如果您看到的不是限制,那么猜测 Keycloak 遵守 RFC6749 并要求您在令牌刷新请求中发送客户端凭据。

    【讨论】:

    • 是的,很遗憾,客户类型是保密的,并迫使我们发送所有凭据。非常感谢!
    猜你喜欢
    • 2021-01-22
    • 2018-03-29
    • 2020-09-01
    • 2020-08-14
    • 2021-05-13
    • 2017-07-18
    • 2018-12-08
    • 2022-01-21
    • 2021-04-19
    相关资源
    最近更新 更多