Browse Source
Merge pull request #201 from schaarj/delete_realm_roles
add delete_realm_roles_of_user function
pull/245/head^2
Marcos Pereira
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
18 additions and
0 deletions
-
docs/source/index.rst
-
keycloak/keycloak_admin.py
|
|
@ -262,6 +262,9 @@ Main methods:: |
|
|
|
# Assign realm roles to user. Note that BOTH role_name and role_id appear to be required. |
|
|
|
keycloak_admin.assign_realm_roles(client_id="client_id", user_id="user_id", roles=[{"roles_representation"}]) |
|
|
|
|
|
|
|
# Delete realm roles of user. Note that BOTH role_name and role_id appear to be required. |
|
|
|
keycloak_admin.deletes_realm_roles_of_user(user_id="user_id", roles=[{"roles_representation"}]) |
|
|
|
|
|
|
|
# Create new group |
|
|
|
group = keycloak_admin.create_group(name="Example Group") |
|
|
|
|
|
|
|
|
|
@ -1244,6 +1244,21 @@ class KeycloakAdmin: |
|
|
|
data=json.dumps(payload)) |
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) |
|
|
|
|
|
|
|
def delete_realm_roles_of_user(self, user_id, roles): |
|
|
|
""" |
|
|
|
Deletes realm roles of a user |
|
|
|
|
|
|
|
:param user_id: id of user |
|
|
|
:param roles: roles list or role (use RoleRepresentation) |
|
|
|
:return Keycloak server response |
|
|
|
""" |
|
|
|
|
|
|
|
payload = roles if isinstance(roles, list) else [roles] |
|
|
|
params_path = {"realm-name": self.realm_name, "id": user_id} |
|
|
|
data_raw = self.raw_delete(URL_ADMIN_USER_REALM_ROLES.format(**params_path), |
|
|
|
data=json.dumps(payload)) |
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) |
|
|
|
|
|
|
|
def get_realm_roles_of_user(self, user_id): |
|
|
|
""" |
|
|
|
Get all realm roles for a user. |
|
|
|