我使用 keycloak 服务登录我的网络应用程序。用作具有 oauth 2.0 安全性的后端 spring。当我使用从 keycloak 获得的不记名令牌向邮递员发出请求时,它给了我一个错误 401,并且在
www-Authenticate
条目旁边的答案文本中它告诉我:
Bearer error="invalid_token", error_description="An error occurred while attempting to decode the Jwt: The iss claim is not valid", error_uri="https://tools.ietf.org/html/rfc6750#section-3.1"
.
我该如何解决这个问题?
Spring 配置值必须与
iss
声明值完全相同。即使尾部斜杠(如果有的话)也很重要。
按照 @BenchVue 在评论中写道:在 jwt.io 中打开一个访问令牌 JWT,复制
iss
声明值并将其粘贴到 spring conf 中。
application.properties 中的 OAuth 属性必须与 Keycloak 地址相同:
spring.security.oauth2.resourceserver.jwt.issuer-uri=http://keycloak-IP:Port/auth/realms/XXX