The following way still works as of Keycloak
v21.0.2 but is super uncomfortable, especially in case when one group should be joined and another should be left:
PUT /{realm}/users/{id}/groups/{groupId}
In documentation for UserRepresentation the entry groups
is listed as < string > array
, however fetching user with
GET /{realm}/users/{id}
returns a UserRepresentation
that is lacking the entry groups
(in my case the user was part of a group, so it was not empty).
When updating a user with
PUT /{realm}/users/{id}
with a minimal UserRepresentation
with only groups
defined like this:
{"groups":["cdcb76bd-ebb1-48ef-bec2-a81aad370746"]}
the SuccessCode
204
is returned, but nothing changed (no removing unmentioned group or adding new group).
This is still an active issue as of May 2023, see here: https://github.com/keycloak/keycloak/issues/9354.