2

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?

kostepanych
  • 2,229
  • 9
  • 32
  • 47

1 Answers1

6

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();
dreamcrash
  • 47,137
  • 25
  • 94
  • 117