Skip to content

Commit

Permalink
Merge pull request Peter-Slump#35 from thomas-anderson-bsl/feature/en…
Browse files Browse the repository at this point in the history
…able-adding-realm-roles

Add function to KeycloakAdmin to add a role to a realm
  • Loading branch information
marcospereirampj authored Oct 17, 2019
2 parents a1eb37b + 4404f06 commit 7354481
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions keycloak/keycloak_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,21 @@ def assign_client_role(self, user_id, client_id, roles):
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
Expand Down

0 comments on commit 7354481

Please sign in to comment.