From 638337219c25b45d21f73f2448d0cace09a939c3 Mon Sep 17 00:00:00 2001 From: Marcos Pereira Date: Sun, 16 Dec 2018 13:05:16 -0200 Subject: [PATCH] Fixed the create_client_role and delete_client_role. --- README.md | 2 +- docs/source/conf.py | 4 ++-- docs/source/index.rst | 2 +- keycloak/keycloak_admin.py | 12 +++++++----- setup.py | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index b79147d..ca78866 100644 --- a/README.md +++ b/README.md @@ -191,7 +191,7 @@ role = keycloak_admin.get_client_role(client_id="client_id", role_name="role_nam role_id = keycloak_admin.get_client_role_id(client_id="client_id", role_name="test") # Create client role -keycloak_admin.create_client_role(client_id, "test") +keycloak_admin.create_client_role(client_id='client_id', {'name': 'roleName', 'clientRole': True}) # Assign client role to user. Note that BOTH role_name and role_id appear to be required. keycloak_admin.assign_client_role(client_id="client_id", user_id="user_id", role_id="role_id", role_name="test") diff --git a/docs/source/conf.py b/docs/source/conf.py index e314aa6..aebd8a7 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -60,9 +60,9 @@ author = 'Marcos Pereira' # built documents. # # The short X.Y version. -version = '0.14.3' +version = '0.14.4' # The full version, including alpha/beta/rc tags. -release = '0.14.3' +release = '0.14.4' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/source/index.rst b/docs/source/index.rst index 1123ddd..90e5d8c 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -224,7 +224,7 @@ Main methods:: role_id = keycloak_admin.get_client_role_id(client_id="client_id", role_name="test") # Create client role - keycloak_admin.create_client_role(client_id, "test") + keycloak_admin.create_client_role(client_id="client_id", {'name': 'roleName', 'clientRole': True}) # Get client role id from name role_id = keycloak_admin.get_client_role_id(client_id=client_id, role_name="test") diff --git a/keycloak/keycloak_admin.py b/keycloak/keycloak_admin.py index 52330a0..bed17f8 100644 --- a/keycloak/keycloak_admin.py +++ b/keycloak/keycloak_admin.py @@ -696,32 +696,34 @@ class KeycloakAdmin: role = self.get_client_role(client_id, role_name) return role.get("id") - def create_client_role(self, payload, skip_exists=False): + def create_client_role(self, client_role_id, payload, skip_exists=False): """ Create a client role RoleRepresentation http://www.keycloak.org/docs-api/3.3/rest-api/index.html#_rolerepresentation - :param payload: id of client (not client-id), role_name: name of role + :param client_role_id: id of client (not client-id) + :param payload: RoleRepresentation :return: Keycloak server response (RoleRepresentation) """ - params_path = {"realm-name": self.realm_name, "id": self.client_id} + params_path = {"realm-name": self.realm_name, "id": client_role_id} data_raw = self.connection.raw_post(URL_ADMIN_CLIENT_ROLES.format(**params_path), data=json.dumps(payload)) return raise_error_from_response(data_raw, KeycloakGetError, expected_code=201, skip_exists=skip_exists) - def delete_client_role(self, role_name): + def delete_client_role(self, client_role_id, role_name): """ Create a client role RoleRepresentation http://www.keycloak.org/docs-api/3.3/rest-api/index.html#_rolerepresentation + :param client_role_id: id of client (not client-id) :param role_name: role’s name (not id!) """ - params_path = {"realm-name": self.realm_name, "id": self.client_id, "role-name": role_name} + params_path = {"realm-name": self.realm_name, "id": client_role_id, "role-name": role_name} data_raw = self.connection.raw_delete(URL_ADMIN_CLIENT_ROLE.format(**params_path)) return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) diff --git a/setup.py b/setup.py index e49dd5e..601e303 100644 --- a/setup.py +++ b/setup.py @@ -7,7 +7,7 @@ with open("README.md", "r") as fh: setup( name='python-keycloak', - version='0.14.3', + version='0.14.4', url='https://bitbucket.org/agriness/python-keycloak', license='The MIT License', author='Marcos Pereira',