From f41f122f2501dc64d4e9a510afbdb8c8e2bfd395 Mon Sep 17 00:00:00 2001 From: Armin Felder Date: Sat, 9 Jun 2018 19:12:22 +0200 Subject: [PATCH 1/2] method to get group members --- keycloak/keycloak_admin.py | 15 ++++++++++++++- keycloak/urls_patterns.py | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/keycloak/keycloak_admin.py b/keycloak/keycloak_admin.py index 17e2c12..442a108 100644 --- a/keycloak/keycloak_admin.py +++ b/keycloak/keycloak_admin.py @@ -22,7 +22,7 @@ from .urls_patterns import \ URL_ADMIN_USERS_COUNT, URL_ADMIN_USER, URL_ADMIN_USER_CONSENTS, \ URL_ADMIN_SEND_UPDATE_ACCOUNT, URL_ADMIN_RESET_PASSWORD, URL_ADMIN_SEND_VERIFY_EMAIL, URL_ADMIN_GET_SESSIONS, \ URL_ADMIN_SERVER_INFO, URL_ADMIN_CLIENTS, URL_ADMIN_CLIENT, URL_ADMIN_CLIENT_ROLES, URL_ADMIN_REALM_ROLES, \ - URL_ADMIN_GROUP, URL_ADMIN_GROUPS, URL_ADMIN_GROUP_CHILD, URL_ADMIN_USER_GROUP,\ + URL_ADMIN_GROUP, URL_ADMIN_GROUP_MEMBERS, URL_ADMIN_GROUPS, URL_ADMIN_GROUP_CHILD, URL_ADMIN_USER_GROUP,\ URL_ADMIN_GROUP_PERMISSIONS, URL_ADMIN_USER_CLIENT_ROLES, URL_ADMIN_USER_STORAGE from .keycloak_openid import KeycloakOpenID @@ -333,6 +333,19 @@ class KeycloakAdmin: data_raw = self.connection.raw_get(URL_ADMIN_GROUP.format(**params_path)) return raise_error_from_response(data_raw, KeycloakGetError) + def get_group_members(self, group_id): + """ + Get group by id. Returns full group details + + GroupRepresentation + http://www.keycloak.org/docs-api/3.2/rest-api/#_grouprepresentation + + :return: Keycloak server response (GroupRepresentation) + """ + params_path = {"realm-name": self.realm_name, "id": group_id} + data_raw = self.connection.raw_get(URL_ADMIN_GROUP_MEMBERS.format(**params_path)) + return raise_error_from_response(data_raw, KeycloakGetError) + def get_group_by_name(self, name_or_path, search_in_subgroups=False): """ Get group id based on name or path. diff --git a/keycloak/urls_patterns.py b/keycloak/urls_patterns.py index ce593da..719d08d 100644 --- a/keycloak/urls_patterns.py +++ b/keycloak/urls_patterns.py @@ -42,6 +42,7 @@ URL_ADMIN_GROUPS = "admin/realms/{realm-name}/groups" URL_ADMIN_GROUP = "admin/realms/{realm-name}/groups/{id}" URL_ADMIN_GROUP_CHILD = "admin/realms/{realm-name}/groups/{id}/children" URL_ADMIN_GROUP_PERMISSIONS = "admin/realms/{realm-name}/groups/{id}/management/permissions" +URL_ADMIN_GROUP_MEMBERS = "admin/realms/{realm-name}/groups/{id}/members" URL_ADMIN_CLIENTS = "admin/realms/{realm-name}/clients" URL_ADMIN_CLIENT = "admin/realms/{realm-name}/clients/{id}" From caf3056229282f86cc507883a347d5d2a8c9b0f1 Mon Sep 17 00:00:00 2001 From: Armin Felder Date: Sat, 9 Jun 2018 19:21:06 +0200 Subject: [PATCH 2/2] comments --- keycloak/keycloak_admin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/keycloak/keycloak_admin.py b/keycloak/keycloak_admin.py index 442a108..40b5e12 100644 --- a/keycloak/keycloak_admin.py +++ b/keycloak/keycloak_admin.py @@ -335,12 +335,12 @@ class KeycloakAdmin: def get_group_members(self, group_id): """ - Get group by id. Returns full group details + Get members by group id. Returns group members GroupRepresentation - http://www.keycloak.org/docs-api/3.2/rest-api/#_grouprepresentation + http://www.keycloak.org/docs-api/3.2/rest-api/#_userrepresentation - :return: Keycloak server response (GroupRepresentation) + :return: Keycloak server response (UserRepresentation) """ params_path = {"realm-name": self.realm_name, "id": group_id} data_raw = self.connection.raw_get(URL_ADMIN_GROUP_MEMBERS.format(**params_path))