marcospereirampj / python-keycloak

MIT License
728 stars 303 forks source link

admin.get_groups not returning group attributes #570

Open fvallee-bnx opened 5 months ago

fvallee-bnx commented 5 months ago

reproduced with v4.1.0 and older versions

When calling admin.get_groups, the parent group attributes are missing. attributes are present in subgroups, but not in parent group

For instance with the parent group "parent" containing attributes the response will be like:

[ { "id": "parent", "name": "parent", "path": "/parent", "subGroupCount": 1, "subGroups": [ { "id": "child", "name": "child", "path": "/parent/child", "parentId": "parent", "subGroupCount": 0, "subGroups": [], "attributes": {}, "realmRoles": [], "clientRoles": {}, "access": { "view": true, "viewMembers": true, "manageMembers": true, "manage": true, "manageMembership": true } } ], "access": { "view": true, "viewMembers": true, "manageMembers": true, "manage": true, "manageMembership": true } } ]

Please note that attributes can be retrieved using get_group_by_path('/parent'), but they should be in get_groups too - especially since they are in subGroups!

ryshoooo commented 2 weeks ago

This is expected based on the default parameters given by the Keycloak's admin REST API, see https://www.keycloak.org/docs-api/latest/rest-api/index.html#_groups. The GET /admin/realms/{realm}/groups has briefRepresentation set to true by default, while GET /admin/realms/{realm}/groups/{group-id}/children has the briefRepresentation set to false by default. Not sure why this is the convention the Keycloak team went for, I guess that'd be a fair question to ask them.

You should be able to get all attributes by calling .get_groups(query={"briefRepresentation": "false"}). We can add this as a default into the library for consistency.