Browse Source

Merge pull request #35 from thomas-anderson-bsl/feature/enable-adding-realm-roles

Add function to KeycloakAdmin to add a role to a realm
pull/39/head
Marcos Pereira 5 years ago
committed by GitHub
parent
commit
73544819db
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      keycloak/keycloak_admin.py

15
keycloak/keycloak_admin.py

@ -827,6 +827,21 @@ class KeycloakAdmin:
data=json.dumps(payload))
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204)
def create_realm_role(self, payload, skip_exists=False):
"""
Create a new role for the realm or client
:param realm: realm name (not id)
:param rep: RoleRepresentation https://www.keycloak.org/docs-api/5.0/rest-api/index.html#_rolerepresentation
:return Keycloak server response
"""
params_path = {"realm-name": self.realm_name}
data_raw = self.connection.raw_post(URL_ADMIN_REALM_ROLES.format(**params_path),
data=json.dumps(payload))
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=201, skip_exists=skip_exists)
def assign_realm_roles(self, user_id, client_id, roles):
"""
Assign realm roles to a user

Loading…
Cancel
Save