From 8d6130ea7bc7f3d64176fc32f011a926e14d08e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Weing=C3=A4rtner?= Date: Sat, 9 Mar 2019 19:12:12 -0300 Subject: [PATCH] Create 'get_client_secrets' method --- keycloak/keycloak_admin.py | 18 ++++++++++++++++-- keycloak/urls_patterns.py | 13 +++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/keycloak/keycloak_admin.py b/keycloak/keycloak_admin.py index d6395ad..67fce46 100644 --- a/keycloak/keycloak_admin.py +++ b/keycloak/keycloak_admin.py @@ -37,7 +37,7 @@ from .urls_patterns import URL_ADMIN_SERVER_INFO, URL_ADMIN_CLIENT_AUTHZ_RESOURC URL_ADMIN_REALM_IMPORT, URL_ADMIN_USERS_COUNT, URL_ADMIN_FLOWS, URL_ADMIN_GROUP, URL_ADMIN_CLIENT_AUTHZ_SETTINGS, \ URL_ADMIN_GROUP_MEMBERS, URL_ADMIN_USER_STORAGE, URL_ADMIN_GROUP_PERMISSIONS, URL_ADMIN_IDPS, \ URL_ADMIN_USER_CLIENT_ROLES_AVAILABLE, URL_ADMIN_USERS, URL_ADMIN_CLIENT_SCOPES, \ - URL_ADMIN_CLIENT_SCOPES_ADD_MAPPER, URL_ADMIN_CLIENT_SCOPE + URL_ADMIN_CLIENT_SCOPES_ADD_MAPPER, URL_ADMIN_CLIENT_SCOPE, URL_ADMIN_CLIENT_SECRETS class KeycloakAdmin: @@ -204,7 +204,7 @@ class KeycloakAdmin: :return: user_id """ - users = self.get_users(query={"username": username}) + users = self.get_users(query={"search": username}) return next((user["id"] for user in users if user["username"] == username), None) def get_user(self, user_id): @@ -910,3 +910,17 @@ class KeycloakAdmin: data_raw = self.connection.raw_post(URL_ADMIN_CLIENT_SCOPES_ADD_MAPPER.format(**params_path), data=json.dumps(payload)) return raise_error_from_response(data_raw, KeycloakGetError, expected_code=201) + + def get_client_secrets(self, client_id): + """ + + Get representation of the client secrets + https://www.keycloak.org/docs-api/4.5/rest-api/index.html#_getclientsecret + + :param client_id: id of client (not client-id) + :return: Keycloak server response (ClientRepresentation) + """ + + params_path = {"realm-name": self.realm_name, "id": client_id} + data_raw = self.connection.raw_get(URL_ADMIN_CLIENT_SECRETS.format(**params_path)) + return raise_error_from_response(data_raw, KeycloakGetError) \ No newline at end of file diff --git a/keycloak/urls_patterns.py b/keycloak/urls_patterns.py index 22f9967..d8b8f2d 100644 --- a/keycloak/urls_patterns.py +++ b/keycloak/urls_patterns.py @@ -57,12 +57,13 @@ URL_ADMIN_GROUP_PERMISSIONS = "admin/realms/{realm-name}/groups/{id}/management/ 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}" -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_CLIENT_AUTHZ_RESOURCES = "admin/realms/{realm-name}/clients/{id}/authz/resource-server/resource" -URL_ADMIN_CLIENT_CERTS = "admin/realms/{realm-name}/clients/{id}/certificates/{attr}" +URL_ADMIN_CLIENT = URL_ADMIN_CLIENTS + "/{id}" +URL_ADMIN_CLIENT_SECRETS= URL_ADMIN_CLIENT + "/client-secret" +URL_ADMIN_CLIENT_ROLES = URL_ADMIN_CLIENT + "/roles" +URL_ADMIN_CLIENT_ROLE = URL_ADMIN_CLIENT + "/roles/{role-name}" +URL_ADMIN_CLIENT_AUTHZ_SETTINGS = URL_ADMIN_CLIENT + "/authz/resource-server/settings" +URL_ADMIN_CLIENT_AUTHZ_RESOURCES = URL_ADMIN_CLIENT + "/authz/resource-server/resource" +URL_ADMIN_CLIENT_CERTS = URL_ADMIN_CLIENT + "/certificates/{attr}" URL_ADMIN_CLIENT_SCOPES = "admin/realms/{realm-name}/client-scopes" URL_ADMIN_CLIENT_SCOPE = URL_ADMIN_CLIENT_SCOPES + "/{scope-id}"