From e5e0a4193f46289968f3bfbf7f6306b77721fe00 Mon Sep 17 00:00:00 2001 From: Giovanni Colapinto Date: Sat, 14 Apr 2018 12:39:17 +0100 Subject: [PATCH] Fix bug in get_client_id method. Add get_client_authz_settings method --- keycloak/keycloak_admin.py | 17 +++++++++++++++-- keycloak/urls_patterns.py | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/keycloak/keycloak_admin.py b/keycloak/keycloak_admin.py index 17e2c12..c006e75 100644 --- a/keycloak/keycloak_admin.py +++ b/keycloak/keycloak_admin.py @@ -21,7 +21,7 @@ from keycloak.urls_patterns import URL_ADMIN_CLIENT_ROLE 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_SERVER_INFO, URL_ADMIN_CLIENTS, URL_ADMIN_CLIENT, URL_ADMIN_CLIENT_ROLES, URL_ADMIN_REALM_ROLES, URL_ADMIN_CLIENT_AUTHZ_SETTINGS, \ URL_ADMIN_GROUP, URL_ADMIN_GROUPS, URL_ADMIN_GROUP_CHILD, URL_ADMIN_USER_GROUP,\ URL_ADMIN_GROUP_PERMISSIONS, URL_ADMIN_USER_CLIENT_ROLES, URL_ADMIN_USER_STORAGE @@ -491,11 +491,24 @@ class KeycloakAdmin: clients = self.get_clients() for client in clients: - if client_name == client['name']: + if client_name == client.get('name') or client_name == client.get('clientId'): return client["id"] return None + def get_client_authz_settings(self, client_id): + """ + Get authorization json from client. + + :param client_id: id in ClientRepresentation + http://www.keycloak.org/docs-api/3.3/rest-api/index.html#_clientrepresentation + :return: Keycloak server response + """ + + params_path = {"realm-name": self.realm_name, "id": client_id} + data_raw = self.connection.raw_get(URL_ADMIN_CLIENT_AUTHZ_SETTINGS.format(**params_path)) + return data_raw + def create_client(self, payload): """ Create a client diff --git a/keycloak/urls_patterns.py b/keycloak/urls_patterns.py index ce593da..9cf2459 100644 --- a/keycloak/urls_patterns.py +++ b/keycloak/urls_patterns.py @@ -47,6 +47,7 @@ URL_ADMIN_CLIENTS = "admin/realms/{realm-name}/clients" URL_ADMIN_CLIENT = "admin/realms/{realm-name}/clients/{id}" URL_ADMIN_CLIENT_ROLES = "admin/realms/{realm-name}/clients/{id}/roles" URL_ADMIN_CLIENT_ROLE = "admin/realms/{realm-name}/clients/{id}/roles/{role-name}" +URL_ADMIN_CLIENT_AUTHZ_SETTINGS = "admin/realms/{realm-name}/clients/{id}/authz/resource-server/settings" URL_ADMIN_REALM_ROLES = "admin/realms/{realm-name}/roles"