Iss 声明无效 Keycloak

问题描述 投票:0回答:3

我使用 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 spring-boot authentication jwt keycloak
3个回答
5
投票

Spring 配置值必须与

iss
声明值完全相同。即使尾部斜杠(如果有的话)也很重要。

按照 @BenchVue 在评论中写道:在 jwt.io 中打开一个访问令牌 JWT,复制

iss
声明值并将其粘贴到 spring conf 中。


1
投票

application.properties 中的 OAuth 属性必须与 Keycloak 地址相同:

spring.security.oauth2.resourceserver.jwt.issuer-uri=http://keycloak-IP:Port/auth/realms/XXX

0
投票

就我而言:我用错了

127.0.0.1 代替 localhost

在配置中

spring.security.oauth2.resourceserver.jwt.issuer-uri=http://localhost:8080/realms/master

因为它是 access_token 中的 localHost

© www.soinside.com 2019 - 2024. All rights reserved.