From 56489b392c27e2e0d79eb4a5b30b5698dc221a13 Mon Sep 17 00:00:00 2001 From: Marcos Pereira Date: Thu, 25 Jan 2018 20:30:30 -0200 Subject: [PATCH 1/3] Updated setup. --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index e3c8d2d..bf6a505 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ from setuptools import setup setup( name='python-keycloak', - version='0.11.1', + version='0.12.0', url='https://bitbucket.org/agriness/python-keycloak', license='GNU General Public License - V3', author='Marcos Pereira', From aea0a43ce3d4ded4738e5aa47a7a7f47fef533f7 Mon Sep 17 00:00:00 2001 From: Marcos Pereira Date: Thu, 25 Jan 2018 20:45:47 -0200 Subject: [PATCH 2/3] Updated docks --- docs/source/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/source/index.rst b/docs/source/index.rst index eea1c71..8223ca1 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -65,6 +65,7 @@ Contributors ================== * `Agriness Team `_ +* `Marcos Pereira `_ * `Martin Devlin `_ * `Shon T. Urbas `_ From 638337219c25b45d21f73f2448d0cace09a939c3 Mon Sep 17 00:00:00 2001 From: Marcos Pereira Date: Sun, 16 Dec 2018 13:05:16 -0200 Subject: [PATCH 3/3] 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',