|
@ -1639,6 +1639,63 @@ class KeycloakAdmin: |
|
|
) |
|
|
) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError) |
|
|
|
|
|
|
|
|
|
|
|
def assign_client_roles_to_client_scope(self, client_id, client_roles_owner_id, roles): |
|
|
|
|
|
"""Assign client roles to a client's scope. |
|
|
|
|
|
|
|
|
|
|
|
:param client_id: id of client (not client-id) who is assigned the roles |
|
|
|
|
|
:param client_roles_owner_id: id of client (not client-id) who has the roles |
|
|
|
|
|
: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": client_id, |
|
|
|
|
|
"client": client_roles_owner_id, |
|
|
|
|
|
} |
|
|
|
|
|
data_raw = self.raw_post( |
|
|
|
|
|
urls_patterns.URL_ADMIN_CLIENT_SCOPE_MAPPINGS_CLIENT_ROLES.format(**params_path), |
|
|
|
|
|
data=json.dumps(payload), |
|
|
|
|
|
) |
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[204]) |
|
|
|
|
|
|
|
|
|
|
|
def delete_client_roles_of_client_scope(self, client_id, client_roles_owner_id, roles): |
|
|
|
|
|
"""Delete client roles of a client's scope. |
|
|
|
|
|
|
|
|
|
|
|
:param client_id: id of client (not client-id) who is assigned the roles |
|
|
|
|
|
:param client_roles_owner_id: id of client (not client-id) who has the roles |
|
|
|
|
|
: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": client_id, |
|
|
|
|
|
"client": client_roles_owner_id, |
|
|
|
|
|
} |
|
|
|
|
|
data_raw = self.raw_delete( |
|
|
|
|
|
urls_patterns.URL_ADMIN_CLIENT_SCOPE_MAPPINGS_CLIENT_ROLES.format(**params_path), |
|
|
|
|
|
data=json.dumps(payload), |
|
|
|
|
|
) |
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204]) |
|
|
|
|
|
|
|
|
|
|
|
def get_client_roles_of_client_scope(self, client_id, client_roles_owner_id): |
|
|
|
|
|
"""Get all client roles for a client's scope. |
|
|
|
|
|
|
|
|
|
|
|
:param client_id: id of client (not client-id) |
|
|
|
|
|
:param client_roles_owner_id: id of client (not client-id) who has the roles |
|
|
|
|
|
:return: Keycloak server response (array RoleRepresentation) |
|
|
|
|
|
""" |
|
|
|
|
|
params_path = { |
|
|
|
|
|
"realm-name": self.realm_name, |
|
|
|
|
|
"id": client_id, |
|
|
|
|
|
"client": client_roles_owner_id, |
|
|
|
|
|
} |
|
|
|
|
|
data_raw = self.raw_get( |
|
|
|
|
|
urls_patterns.URL_ADMIN_CLIENT_SCOPE_MAPPINGS_CLIENT_ROLES.format(**params_path) |
|
|
|
|
|
) |
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError) |
|
|
|
|
|
|
|
|
def assign_realm_roles(self, user_id, roles): |
|
|
def assign_realm_roles(self, user_id, roles): |
|
|
"""Assign realm roles to a user. |
|
|
"""Assign realm roles to a user. |
|
|
|
|
|
|
|
|