我可以在JWT令牌中保存自定义信息吗?
我想知道是否有一种方法可以在我的JWT令牌中存储“自定义”信息。
现在,我有一个在KeyCloak中创建的领域,然后当我针对KeyCloak登录时,我会得到我的Access_Token。如果我解码我的access_token,(来自jwt.io),我会获取以下信息:
{
"exp": 1656952366,
"iat": 1656916366,
"jti": "be89285a-dce9-4860-9849-396044b34578",
"iss": "https://dev.domain.com/auth/realms/miREALM",
"aud": "account",
"sub": "95fa9b26-0fc8-48ac-820e-71cb70183c6b",
"typ": "Bearer",
"azp": "MyProject",
"session_state": "ceb61406-as9c-47f4-1461-43a63ebf939d",
"acr": "1",
"realm_access": {
"roles": [
"default-roles-myproduct-myproject",
"offline_access",
"uma_authorization"
]
},
"resource_access": {
"MyProject": {
"roles": [
"admin"
]
},
"account": {
"roles": [
"manage-account",
"manage-account-links",
"view-profile"
]
}
},
"scope": "openid mapPermissions profile email",
"realm-management": {},
"email_verified": false,
"security-admin-console": {},
"MyPRoject": {},
"preferred_username": "[email protected]",
"account-console": {},
"given_name": "Mark",
"broker": {},
"name": "Mark",
"admin-cli": {},
"family_name": "Mark",
"email": "[email protected]",
"account": {}
}
我想知道是否有任何使用自定义信息创建一些节点。 例如,我希望能够保存用户寿命的地址,因此我不必访问我的数据库来检索它。
I would like to know if there is a way to store "custom" information in my JWT token.
Right now I have a REALM created in Keycloak, then when I login against Keycloak, I get my access_token. If I decode my access_token, (from jwt.io) I obtain information like:
{
"exp": 1656952366,
"iat": 1656916366,
"jti": "be89285a-dce9-4860-9849-396044b34578",
"iss": "https://dev.domain.com/auth/realms/miREALM",
"aud": "account",
"sub": "95fa9b26-0fc8-48ac-820e-71cb70183c6b",
"typ": "Bearer",
"azp": "MyProject",
"session_state": "ceb61406-as9c-47f4-1461-43a63ebf939d",
"acr": "1",
"realm_access": {
"roles": [
"default-roles-myproduct-myproject",
"offline_access",
"uma_authorization"
]
},
"resource_access": {
"MyProject": {
"roles": [
"admin"
]
},
"account": {
"roles": [
"manage-account",
"manage-account-links",
"view-profile"
]
}
},
"scope": "openid mapPermissions profile email",
"realm-management": {},
"email_verified": false,
"security-admin-console": {},
"MyPRoject": {},
"preferred_username": "[email protected]",
"account-console": {},
"given_name": "Mark",
"broker": {},
"name": "Mark",
"admin-cli": {},
"family_name": "Mark",
"email": "[email protected]",
"account": {}
}
I would like to know if there is any way to create some node with custom information.
For example, I would like to be able to save the address where the user lives, so I don't have to access my database to retrieve it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将映射器添加到客户端/客户端范围。
您可以使用不同的类型。在您的情况下,“用户属性”将是最佳选择。
You can add a mapper to the client/client scope.
There are different types that you can use. In your case "User Attribute" will be the best choise.