Keycloak - Add roles to the user profile

Viewed 798

I am using keycloak on one of my projects. On the backend I am using sringboot and calling Keycloak REST API.

I would love to have info about roles (better would be client's roles, but realm roles will be sufficient) of each users, when fetching it's profile.

URL where I am trying to fetch user: <host>/admin/realms/<realm>/users/<id>

At this moment, I have to programmatically loop over each user and fetch his roles. Which means many and many additional requests. Imagine having 500 users... And yes, I know I could paginate them etc.

I have been trying to find something on the internet for sooo long time, but nothing works. I am able to add them to the access token, but I can't add them to the user info.

If there is anyone who knows how to enrich user info, just point me the right directions. I have been messing with client scopes for so long and I still don't understand them at all. I could not even find a good tutorial on this topic..

1 Answers
Related