oauth-2.0 - [OAuth][Keycloak] 尝试使用 refresh_token 时,invalid_grant 会话不活动
问题描述
我正在尝试使用 ClientOAuth2.Token.refresh() 刷新 oauth2 令牌,但有时会不断收到错误消息:
{"error":"invalid_grant","error_description":"Session not active"}
这是我由 Fiddler 捕获的请求
POST [URL]= HTTP/1.1
Host: [URL]
Connection: keep-alive
Content-Length: 2250
Accept: application/json, application/x-www-form-urlencoded
Origin: http://localhost:8080
Authorization: Basic YXNpbW92LWRldi1laGlzLXdlYjo=
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36
Sec-Fetch-Mode: cors
Content-Type: application/x-www-form-urlencoded
Sec-Fetch-Site: cross-site
Referer: http://localhost:8080/
Accept-Encoding: gzip, deflate, br
Accept-Language: en,vi;q=0.9,de;q=0.8,vi-VN;q=0.7,en-US;q=0.6,en-AU;q=0.5
refresh_token=[token]&grant_type=refresh_token
我在 KeyCloak 帐户上的设置可能有问题。有什么建议吗?
解决方案
您需要在检索原始令牌时添加范围offline_access,否则当相关用户会话不活动时您将无法刷新它(这是特定于OIDC,而不是oauth2)。
推荐阅读
- amazon-s3 - 从命令式 try-with-resource 转变为反应式 using, using()
- spring-boot - Spring Boot 2.2.6 Java 应用程序在错误的数据库上执行 sql 查询
- stored-procedures - 用于更新超过 1 000 000 行的 Pl/Sql 脚本
- facebook-ads - 如何从 App Store 下载 - 链接到 Facebook 帖子?
- clickhouse - 有没有办法做clickhouse索引和分区分析
- amazon-web-services - 将旧的 tfstate 用于 terraform 破坏目的
- ios - 清除 Xamarin iOS 中的 Cookie 构建 NHttpCookieStorage 不清除 WebView 的 Cookie
- python - 使用 python 在 student-t 分布表中搜索值
- python - 我们如何通过扩展类在 Python 中结合抽象方法和自定义异常?
- c - Cooja 中的浮点计算