Browse Source

Merged in develop (pull request #26)

Develop

Approved-by: Marcos Pereira <marcospereira.mpj@gmail.com>
pull/12/head
Marcos Pereira 6 years ago
parent
commit
3980ec8835
  1. 2
      README.md
  2. 4
      docs/source/conf.py
  3. 2
      docs/source/index.rst
  4. 12
      keycloak/keycloak_admin.py
  5. 2
      setup.py

2
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")

4
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.

2
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")

12
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: roles 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)

2
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',

Loading…
Cancel
Save