I have also tried to get this information in the scope of one call since based on the Keycloak API documentation we can do it. But no results. I have also tried to use different Mappers for the client using which we can add some information to the token data, user info, and so on. But Looks like we can not get that information using the GET /auth/admin/realms/{realm}/users
endpoint. it's not working also for the GET /auth/admin/realms/{realm}/users/{userId}
endpoint.
In my case, I need to get the users list, with pagination and search option, and I need information about the client roles which are assigned to the user, and groups on which the user is in.
Due to that, I need to make a lot of API calls. I need to get users list, then for each user, I need to get users groups, and client roles by additional API calls, and then combine that information. Also, make an API call to get users to count. BUT, It's not really to have more than 20 API calls to get needed information for 10 users.
So, what I did.
As an alternative way, I have connected my Nest.js application to the Keycloak database directly and did what I need by one SQL query using TypeORM. I have created the models, with relations and did it so easily.
In my case, I have used USER_ENTITY
, USER_ROLE_MAPPING
, KEYCLOAK_ROLE
, USER_GROUP_MEMBERSHIP
, KEYCLOAK_GROUP
tables.
Its works were good. The only thing is that maybe, in future Keycloak versions, can add some changes in the DB structure...
In that case, changes should be investigated and the Keycloak version should be updated after changes in the models.
If you are doing something like my solution, be sure that you are not changing anything in the Keycloak database. Or, if you want to do inserting or removing operations without using Keycloak API, be sure that you have all information about the Keycloak database structure. There are actually about 93 tables.