刷新 Keycloak 离线令牌

Refreshing Keycloak offline token

我目前正在尝试获取与 Keycloak 一起使用的离线令牌。我的问题是,我无法刷新我曾经收到的令牌..

当我最初调用令牌端点时,我得到了带有有效访问令牌的正确响应:

{
  "access_token": "<access-token>",
  "expires_in": 900,
  "refresh_expires_in": 0,
  "refresh_token": "<refresh-token>",
  "token_type": "bearer",
  "not-before-policy": 1539890980,
  "session_state": "a178faf2-xxxx-xxxx-xxxx-fb16548b6805",
  "scope": "email profile offline_access"
}

然后,我尝试使用

刷新令牌
curl -X POST \
  https://<my-url>/auth/realms/<realm>/protocol/openid-connect/token \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'cache-control: no-cache' \
  -d 'client_id=<client-id>
  -d 'refresh_token=<refresh-token>
  -d 'grant_type=refresh_token'

我收到以下错误:

{
  "error": "invalid_grant",
  "error_description": "Offline session not active"
}

我查看了 Keycloaks Jira 问题,这似乎不是已知问题。任何人都可以帮助我获得离线令牌 运行 吗?有什么特别的技巧吗?感谢您的帮助!

确保您的离线会话领域设置值大于 0。它们的生命周期与正常会话不同。

默认情况下,我认为它设置为 30 天,但请仔细检查。

然后检查领域设置,看看是否也允许重复使用刷新令牌。如果您禁用了令牌的重复使用,请确保您不会多次使用刷新令牌。

如果重新使用被关闭,那么我现在就没有想到什么了。我只在令牌过期时看到您的错误。