英文:
How to get user details from keycloak (not logged in user but any user by his id)
问题
在我的使用Spring Boot的Java Web应用中,我已经完成了Keycloak身份验证,但现在我需要通过用户ID(非当前登录用户)获取某个用户的用户详细信息。这可行吗?我想从Java代码中获取他的角色、群组和数据。
英文:
In my Java web application with Spring Boot I have Keycloak authentication done but now I need to get user details of some user by id (not user that is logged in). Is it possible ? I want to get his roles, groups and data from Java code.
答案1
得分: 1
@POST ${yourHost}/auth/realms/${yourRealm}/protocol/openid-connect/token
with @RequestBody
{
"client_id": "admin-cli",
"username": "admin",
"password": "secret",
"grant_type": "password"
}
Then, call ${_HOST}/auth/admin/realms/${_REALM}/users
using that token as a Header's parameter "Authorization: bearer " + ${_TOKEN}
Do the same to get userByID, but by calling: ${_HOST}/auth/admin/realms/${_REALM}/users/${_USER_ID}
英文:
You can use the REST API by getting an access token from:
@POST ${yourHost}/auth/realms/${yourRealm}/protocol/openid-connect/token
with @RequestBody
{
"client_id": "admin-cli",
"username": "admin",
"password": "secret",
"grant_type": "password"
}
Then, call ${_HOST}/auth/admin/realms/${_REALM}/users
using that token as a Header's parameter "Authorization: bearer " + ${_TOKEN}
Do the same to get userByID, but by calling: ${_HOST}/auth/admin/realms/${_REALM}/users/${_USER_ID}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论