【发布时间】:2020-01-19 16:23:51
【问题描述】:
如何获取 keycloak 中 userinfo 端点回复中包含的角色。我在 keycloak 中为用户定义了一个“角色映射”。当我调用 userinfo 端点时,我会得到电子邮件名称等字段,但回复中不包含角色。当我调用 auth 端点时,我得到 access_token 并且在字段范围内包含角色。以下是来自 auth 端点的回复:
access_token" QJsonValue(string, "eyJhb...")
"expires_in" QJsonValue(double, 300)
"not-before-policy" QJsonValue(double, 0)
"refresh_expires_in" QJsonValue(double, 1800)
"refresh_token" QJsonValue(string, "eyJhb...")
"scope" QJsonValue(string, "profile email roles")
"session_state" QJsonValue(string, "20b48536-4b38-4aa6-9072-e8309833402e")
"token_type" QJsonValue(string, "bearer")
我还尝试使用属性“scope=roles”调用 userinfo 端点,但这不起作用。
【问题讨论】:
-
如果您未解析 accessToken,则您分配给的所有客户端都有用户角色。 stackoverflow.com/questions/38552003/…
-
Bumblebee,我可以在这里帮助你,但我需要更多细节,所以有几个问题: 1. 你能看到解码令牌中的角色吗? - 尝试jwt.io 解码您的令牌 2. 您如何尝试从令牌中提取字段 - 通过 javascript 库或 Java 库?
-
tryingToLearn,是的,我可以在 jwt.io 中解码令牌,也可以看到角色。我想提取 Qt5 C++ 应用程序中的字段。