Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search users inside group in Keycloak?

Using Keycloak 11.0.3. I trying to search users inside group using Keycloak API:

List<UserRepresentation>  users = realmResource.users().search(username, firstname, lastname, email,
    0, 100);

But when I try to get groups of found users I get null even if user have group:

List<String> groups = users.get(0).getGroups(); //It's null

So how to search users inside group?

like image 639
kostepanych Avatar asked Oct 17 '25 11:10

kostepanych


1 Answers

To get the groups that a user belongs to try with the following:

realm.users().get(userId).groups();

Use the userID instead.

To get the users of a given group do the following:

realm.groups().group(groupId).members();
like image 113
dreamcrash Avatar answered Oct 20 '25 01:10

dreamcrash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!