Reputation: 1042
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.
Upvotes: 0
Views: 2819
Reputation: 41
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}
Upvotes: 1