How to get user details from keycloak (not logged in user but any user by his id)

huangapple go评论79阅读模式
英文:

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}

huangapple
  • 本文由 发表于 2020年5月29日 17:25:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/62082685.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定