【发布时间】:2020-11-24 18:41:42
【问题描述】:
我有两个在本地运行的 Keycloak 实例。它们通过 OIDC 连接。到目前为止一切正常 - 我可以通过任何 Keycloak 实例登录。
现在我正在尝试设置 token exchage,但它失败并出现“invalid_token”错误。我想做“外部到内部”的令牌交换。以下 Keycloak 日志显示 Keycloak 使用我提供给另一个 Keycloak 实例的令牌发送 HTTP GET 请求以获取用户信息:
08:14:36,523 DEBUG http-outgoing-19 >> "GET /auth/realms/master/protocol/openid-connect/userinfo HTTP/1.1[\r][\n]"
08:14:36,523 DEBUG http-outgoing-19 >> "Authorization: Bearer eyJhbGciOiJSU...[\r][\n]"
响应是 401:
08:14:36,530 DEBUG http-outgoing-19 << "HTTP/1.1 401 Unauthorized[\r][\n]"
08:14:36,530 DEBUG http-outgoing-19 << "X-XSS-Protection: 1; mode=block[\r][\n]"
08:14:36,530 DEBUG http-outgoing-19 << "X-Frame-Options: SAMEORIGIN[\r][\n]"
08:14:36,530 DEBUG http-outgoing-19 << "Referrer-Policy: no-referrer[\r][\n]"
08:14:36,530 DEBUG http-outgoing-19 << "Date: Tue, 24 Nov 2020 08:14:36 GMT[\r][\n]"
08:14:36,530 DEBUG http-outgoing-19 << "Connection: keep-alive[\r][\n]"
08:14:36,530 DEBUG http-outgoing-19 << "WWW-Authenticate: Bearer realm="master", error="invalid_token", error_description="Token verification failed"[\r][\n]"
奇怪的是:当我使用在 Keycloak 中不起作用的相同令牌发送与 curl 相同的响应时 - 它起作用了:
curl -X GET 'http://localhost:8050/auth/realms/master/protocol/openid-connect/userinfo' \
-H 'Authorization: Bearer eyJhbGciOiJSUzI1N...'
{"name":"r o","sub":"fff41a6f-6910-4419-8d46-7630b57ed420","email_verified":true,"preferred_username":"ttt","given_name":"r","family_name":"o"}
设置了令牌交换的所有权限(否则它根本不发送请求并且失败并出现另一个错误)。
我在这里缺少什么?非常感谢任何帮助。
【问题讨论】:
标签: oauth keycloak openid-connect openid