【发布时间】:2021-07-20 05:02:25
【问题描述】:
我使用 Keycloak 对用户进行身份验证。我创建了新领域(Efairy-realm)、客户端(efairy-backend)和新角色(user、moderator em>,管理员)。看起来是这样的:
Config 1 look like this. Config 2 look like this.
问题从access_token开始:
{
"exp": 1619466995,
"iat": 1619466935,
"jti": "fcd20273-fb45-408c-9e20-126653d69719",
"iss": "http://localhost:8082/auth/realms/efairy-realm",
"aud": "account",
"sub": "b1d89dc2-c12d-4c80-beed-c9a6065ec604",
"typ": "Bearer",
"azp": "efairy-backend",
"session_state": "d4a2b283-2f54-4a17-9a27-99db26278ba7",
"acr": "1",
"allowed-origins": [
"",
"http://localhost:8083"
],
"realm_access": {
"roles": [
"offline_access",
"uma_authorization"
]
},
"resource_access": {
"efairy-backend": {
"roles": [
"uma_protection",
"user"
]
},
"account": {
"roles": [
"manage-account",
"manage-account-links",
"view-profile"
]
}
},
"scope": "profile roles email",
"clientHost": "172.23.0.1",
"email_verified": false,
"clientId": "efairy-backend",
"groups": [
"offline_access",
"uma_authorization"
],
"preferred_username": "service-account-efairy-backend",
"clientAddress": "172.23.0.1"
}
我创建了名为 moderator 的新用户,角色为 moderator,当我登录该用户时,我正在接收角色(resource_access.efairy-backend.roles )我在选项卡 Service Account Roles 中设置,但我想在 Role Mappings 选项卡。
登录流程如下所示:
-
我使用这些参数将用户从我的前端应用程序重定向到 keyclock 登录页面:/auth/realms/efiary-realm/protocol/openid-connect/auth?response_type=code&client_id=eairy-backend&redirect_uri=http:// localhost:8083/auth-redirect-url
-
然后我输入正确的用户名和密码,然后点击登录
-
在我重定向到前端应用程序中成功唱歌后,并使用参数请求令牌: /auth/realms/efairy-realm/protocol/openid-connect/token
grant_type:client_credentials
client_id:efairy-backend >
client_secret:
代码: -
回复:
access_token: "eyJhbGciO...AjbA",
expires_in: 60,
非之前政策:1619128217,
refresh_expires_in:1799,
refresh_token: "eyJ...XQ_R0",
范围:“个人资料角色电子邮件”,
session_state: "fcf1391d-...b11795c03f80",
token_type: "承载者",
有人知道怎么解决吗? :)
【问题讨论】:
标签: jwt authorization keycloak