|
@ -237,7 +237,7 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
data_raw = self.raw_post(URL_ADMIN_REALMS, |
|
|
data_raw = self.raw_post(URL_ADMIN_REALMS, |
|
|
data=json.dumps(payload)) |
|
|
data=json.dumps(payload)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=201) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201]) |
|
|
|
|
|
|
|
|
def get_realms(self): |
|
|
def get_realms(self): |
|
|
""" |
|
|
""" |
|
@ -262,7 +262,7 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
data_raw = self.raw_post(URL_ADMIN_REALMS, |
|
|
data_raw = self.raw_post(URL_ADMIN_REALMS, |
|
|
data=json.dumps(payload)) |
|
|
data=json.dumps(payload)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=201, skip_exists=skip_exists) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists) |
|
|
|
|
|
|
|
|
def update_realm(self, realm_name, payload): |
|
|
def update_realm(self, realm_name, payload): |
|
|
""" |
|
|
""" |
|
@ -340,7 +340,7 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
data_raw = self.raw_post(URL_ADMIN_USERS.format(**params_path), |
|
|
data_raw = self.raw_post(URL_ADMIN_USERS.format(**params_path), |
|
|
data=json.dumps(payload)) |
|
|
data=json.dumps(payload)) |
|
|
raise_error_from_response(data_raw, KeycloakGetError, expected_code=201) |
|
|
|
|
|
|
|
|
raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201]) |
|
|
_last_slash_idx = data_raw.headers['Location'].rindex('/') |
|
|
_last_slash_idx = data_raw.headers['Location'].rindex('/') |
|
|
return data_raw.headers['Location'][_last_slash_idx + 1:] |
|
|
return data_raw.headers['Location'][_last_slash_idx + 1:] |
|
|
|
|
|
|
|
@ -409,7 +409,7 @@ class KeycloakAdmin: |
|
|
params_path = {"realm-name": self.realm_name, "id": user_id} |
|
|
params_path = {"realm-name": self.realm_name, "id": user_id} |
|
|
data_raw = self.raw_put(URL_ADMIN_USER.format(**params_path), |
|
|
data_raw = self.raw_put(URL_ADMIN_USER.format(**params_path), |
|
|
data=json.dumps(payload)) |
|
|
data=json.dumps(payload)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) |
|
|
|
|
|
|
|
|
def delete_user(self, user_id): |
|
|
def delete_user(self, user_id): |
|
|
""" |
|
|
""" |
|
@ -421,7 +421,7 @@ class KeycloakAdmin: |
|
|
""" |
|
|
""" |
|
|
params_path = {"realm-name": self.realm_name, "id": user_id} |
|
|
params_path = {"realm-name": self.realm_name, "id": user_id} |
|
|
data_raw = self.raw_delete(URL_ADMIN_USER.format(**params_path)) |
|
|
data_raw = self.raw_delete(URL_ADMIN_USER.format(**params_path)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) |
|
|
|
|
|
|
|
|
def set_user_password(self, user_id, password, temporary=True): |
|
|
def set_user_password(self, user_id, password, temporary=True): |
|
|
""" |
|
|
""" |
|
@ -441,7 +441,7 @@ class KeycloakAdmin: |
|
|
params_path = {"realm-name": self.realm_name, "id": user_id} |
|
|
params_path = {"realm-name": self.realm_name, "id": user_id} |
|
|
data_raw = self.raw_put(URL_ADMIN_RESET_PASSWORD.format(**params_path), |
|
|
data_raw = self.raw_put(URL_ADMIN_RESET_PASSWORD.format(**params_path), |
|
|
data=json.dumps(payload)) |
|
|
data=json.dumps(payload)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) |
|
|
|
|
|
|
|
|
def consents_user(self, user_id): |
|
|
def consents_user(self, user_id): |
|
|
""" |
|
|
""" |
|
@ -658,7 +658,7 @@ class KeycloakAdmin: |
|
|
data_raw = self.raw_post(URL_ADMIN_GROUP_CHILD.format(**params_path), |
|
|
data_raw = self.raw_post(URL_ADMIN_GROUP_CHILD.format(**params_path), |
|
|
data=json.dumps(payload)) |
|
|
data=json.dumps(payload)) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=201, skip_exists=skip_exists) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists) |
|
|
|
|
|
|
|
|
def update_group(self, group_id, payload): |
|
|
def update_group(self, group_id, payload): |
|
|
""" |
|
|
""" |
|
@ -676,7 +676,7 @@ class KeycloakAdmin: |
|
|
params_path = {"realm-name": self.realm_name, "id": group_id} |
|
|
params_path = {"realm-name": self.realm_name, "id": group_id} |
|
|
data_raw = self.raw_put(URL_ADMIN_GROUP.format(**params_path), |
|
|
data_raw = self.raw_put(URL_ADMIN_GROUP.format(**params_path), |
|
|
data=json.dumps(payload)) |
|
|
data=json.dumps(payload)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) |
|
|
|
|
|
|
|
|
def group_set_permissions(self, group_id, enabled=True): |
|
|
def group_set_permissions(self, group_id, enabled=True): |
|
|
""" |
|
|
""" |
|
@ -703,7 +703,7 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
params_path = {"realm-name": self.realm_name, "id": user_id, "group-id": group_id} |
|
|
params_path = {"realm-name": self.realm_name, "id": user_id, "group-id": group_id} |
|
|
data_raw = self.raw_put(URL_ADMIN_USER_GROUP.format(**params_path), data=None) |
|
|
data_raw = self.raw_put(URL_ADMIN_USER_GROUP.format(**params_path), data=None) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) |
|
|
|
|
|
|
|
|
def group_user_remove(self, user_id, group_id): |
|
|
def group_user_remove(self, user_id, group_id): |
|
|
""" |
|
|
""" |
|
@ -716,7 +716,7 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
params_path = {"realm-name": self.realm_name, "id": user_id, "group-id": group_id} |
|
|
params_path = {"realm-name": self.realm_name, "id": user_id, "group-id": group_id} |
|
|
data_raw = self.raw_delete(URL_ADMIN_USER_GROUP.format(**params_path)) |
|
|
data_raw = self.raw_delete(URL_ADMIN_USER_GROUP.format(**params_path)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) |
|
|
|
|
|
|
|
|
def delete_group(self, group_id): |
|
|
def delete_group(self, group_id): |
|
|
""" |
|
|
""" |
|
@ -728,7 +728,7 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
params_path = {"realm-name": self.realm_name, "id": group_id} |
|
|
params_path = {"realm-name": self.realm_name, "id": group_id} |
|
|
data_raw = self.raw_delete(URL_ADMIN_GROUP.format(**params_path)) |
|
|
data_raw = self.raw_delete(URL_ADMIN_GROUP.format(**params_path)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) |
|
|
|
|
|
|
|
|
def get_clients(self): |
|
|
def get_clients(self): |
|
|
""" |
|
|
""" |
|
@ -817,7 +817,7 @@ class KeycloakAdmin: |
|
|
params_path = {"realm-name": self.realm_name} |
|
|
params_path = {"realm-name": self.realm_name} |
|
|
data_raw = self.raw_post(URL_ADMIN_CLIENTS.format(**params_path), |
|
|
data_raw = self.raw_post(URL_ADMIN_CLIENTS.format(**params_path), |
|
|
data=json.dumps(payload)) |
|
|
data=json.dumps(payload)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=201, skip_exists=skip_exists) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists) |
|
|
|
|
|
|
|
|
def update_client(self, client_id, payload): |
|
|
def update_client(self, client_id, payload): |
|
|
""" |
|
|
""" |
|
@ -831,7 +831,7 @@ class KeycloakAdmin: |
|
|
params_path = {"realm-name": self.realm_name, "id": client_id} |
|
|
params_path = {"realm-name": self.realm_name, "id": client_id} |
|
|
data_raw = self.raw_put(URL_ADMIN_CLIENT.format(**params_path), |
|
|
data_raw = self.raw_put(URL_ADMIN_CLIENT.format(**params_path), |
|
|
data=json.dumps(payload)) |
|
|
data=json.dumps(payload)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) |
|
|
|
|
|
|
|
|
def delete_client(self, client_id): |
|
|
def delete_client(self, client_id): |
|
|
""" |
|
|
""" |
|
@ -846,7 +846,7 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
params_path = {"realm-name": self.realm_name, "id": client_id} |
|
|
params_path = {"realm-name": self.realm_name, "id": client_id} |
|
|
data_raw = self.raw_delete(URL_ADMIN_CLIENT.format(**params_path)) |
|
|
data_raw = self.raw_delete(URL_ADMIN_CLIENT.format(**params_path)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) |
|
|
|
|
|
|
|
|
def get_realm_roles(self): |
|
|
def get_realm_roles(self): |
|
|
""" |
|
|
""" |
|
@ -929,7 +929,7 @@ class KeycloakAdmin: |
|
|
params_path = {"realm-name": self.realm_name, "id": client_role_id} |
|
|
params_path = {"realm-name": self.realm_name, "id": client_role_id} |
|
|
data_raw = self.raw_post(URL_ADMIN_CLIENT_ROLES.format(**params_path), |
|
|
data_raw = self.raw_post(URL_ADMIN_CLIENT_ROLES.format(**params_path), |
|
|
data=json.dumps(payload)) |
|
|
data=json.dumps(payload)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=201, skip_exists=skip_exists) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists) |
|
|
|
|
|
|
|
|
def delete_client_role(self, client_role_id, role_name): |
|
|
def delete_client_role(self, client_role_id, role_name): |
|
|
""" |
|
|
""" |
|
@ -943,7 +943,7 @@ class KeycloakAdmin: |
|
|
""" |
|
|
""" |
|
|
params_path = {"realm-name": self.realm_name, "id": client_role_id, "role-name": role_name} |
|
|
params_path = {"realm-name": self.realm_name, "id": client_role_id, "role-name": role_name} |
|
|
data_raw = self.raw_delete(URL_ADMIN_CLIENT_ROLE.format(**params_path)) |
|
|
data_raw = self.raw_delete(URL_ADMIN_CLIENT_ROLE.format(**params_path)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) |
|
|
|
|
|
|
|
|
def assign_client_role(self, user_id, client_id, roles): |
|
|
def assign_client_role(self, user_id, client_id, roles): |
|
|
""" |
|
|
""" |
|
@ -959,7 +959,7 @@ class KeycloakAdmin: |
|
|
params_path = {"realm-name": self.realm_name, "id": user_id, "client-id": client_id} |
|
|
params_path = {"realm-name": self.realm_name, "id": user_id, "client-id": client_id} |
|
|
data_raw = self.raw_post(URL_ADMIN_USER_CLIENT_ROLES.format(**params_path), |
|
|
data_raw = self.raw_post(URL_ADMIN_USER_CLIENT_ROLES.format(**params_path), |
|
|
data=json.dumps(payload)) |
|
|
data=json.dumps(payload)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) |
|
|
|
|
|
|
|
|
def create_realm_role(self, payload, skip_exists=False): |
|
|
def create_realm_role(self, payload, skip_exists=False): |
|
|
""" |
|
|
""" |
|
@ -973,7 +973,7 @@ class KeycloakAdmin: |
|
|
params_path = {"realm-name": self.realm_name} |
|
|
params_path = {"realm-name": self.realm_name} |
|
|
data_raw = self.raw_post(URL_ADMIN_REALM_ROLES.format(**params_path), |
|
|
data_raw = self.raw_post(URL_ADMIN_REALM_ROLES.format(**params_path), |
|
|
data=json.dumps(payload)) |
|
|
data=json.dumps(payload)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=201, skip_exists=skip_exists) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists) |
|
|
|
|
|
|
|
|
def update_realm_role(self, role_name, payload): |
|
|
def update_realm_role(self, role_name, payload): |
|
|
""" |
|
|
""" |
|
@ -1014,7 +1014,7 @@ class KeycloakAdmin: |
|
|
params_path = {"realm-name": self.realm_name, "id": user_id} |
|
|
params_path = {"realm-name": self.realm_name, "id": user_id} |
|
|
data_raw = self.raw_post(URL_ADMIN_USER_REALM_ROLES.format(**params_path), |
|
|
data_raw = self.raw_post(URL_ADMIN_USER_REALM_ROLES.format(**params_path), |
|
|
data=json.dumps(payload)) |
|
|
data=json.dumps(payload)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) |
|
|
|
|
|
|
|
|
def assign_group_realm_roles(self, group_id, roles): |
|
|
def assign_group_realm_roles(self, group_id, roles): |
|
|
""" |
|
|
""" |
|
@ -1029,7 +1029,7 @@ class KeycloakAdmin: |
|
|
params_path = {"realm-name": self.realm_name, "id": group_id} |
|
|
params_path = {"realm-name": self.realm_name, "id": group_id} |
|
|
data_raw = self.raw_post(URL_ADMIN_GROUPS_REALM_ROLES.format(**params_path), |
|
|
data_raw = self.raw_post(URL_ADMIN_GROUPS_REALM_ROLES.format(**params_path), |
|
|
data=json.dumps(payload)) |
|
|
data=json.dumps(payload)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) |
|
|
|
|
|
|
|
|
def delete_group_realm_roles(self, group_id, roles): |
|
|
def delete_group_realm_roles(self, group_id, roles): |
|
|
""" |
|
|
""" |
|
@ -1044,7 +1044,7 @@ class KeycloakAdmin: |
|
|
params_path = {"realm-name": self.realm_name, "id": group_id} |
|
|
params_path = {"realm-name": self.realm_name, "id": group_id} |
|
|
data_raw = self.raw_delete(URL_ADMIN_GROUPS_REALM_ROLES.format(**params_path), |
|
|
data_raw = self.raw_delete(URL_ADMIN_GROUPS_REALM_ROLES.format(**params_path), |
|
|
data=json.dumps(payload)) |
|
|
data=json.dumps(payload)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) |
|
|
|
|
|
|
|
|
def get_group_realm_roles(self, group_id): |
|
|
def get_group_realm_roles(self, group_id): |
|
|
""" |
|
|
""" |
|
@ -1152,7 +1152,7 @@ class KeycloakAdmin: |
|
|
params_path = {"realm-name": self.realm_name, "id": user_id, "client-id": client_id} |
|
|
params_path = {"realm-name": self.realm_name, "id": user_id, "client-id": client_id} |
|
|
data_raw = self.raw_delete(URL_ADMIN_USER_CLIENT_ROLES.format(**params_path), |
|
|
data_raw = self.raw_delete(URL_ADMIN_USER_CLIENT_ROLES.format(**params_path), |
|
|
data=json.dumps(payload)) |
|
|
data=json.dumps(payload)) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) |
|
|
|
|
|
|
|
|
def get_authentication_flows(self): |
|
|
def get_authentication_flows(self): |
|
|
""" |
|
|
""" |
|
@ -1182,7 +1182,7 @@ class KeycloakAdmin: |
|
|
params_path = {"realm-name": self.realm_name} |
|
|
params_path = {"realm-name": self.realm_name} |
|
|
data_raw = self.raw_post(URL_ADMIN_FLOWS.format(**params_path), |
|
|
data_raw = self.raw_post(URL_ADMIN_FLOWS.format(**params_path), |
|
|
data=payload) |
|
|
data=payload) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=201, skip_exists=skip_exists) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists) |
|
|
|
|
|
|
|
|
def get_authentication_flow_executions(self, flow_alias): |
|
|
def get_authentication_flow_executions(self, flow_alias): |
|
|
""" |
|
|
""" |
|
@ -1210,7 +1210,7 @@ class KeycloakAdmin: |
|
|
params_path = {"realm-name": self.realm_name, "flow-alias": flow_alias} |
|
|
params_path = {"realm-name": self.realm_name, "flow-alias": flow_alias} |
|
|
data_raw = self.raw_put(URL_ADMIN_FLOWS_EXECUTIONS.format(**params_path), |
|
|
data_raw = self.raw_put(URL_ADMIN_FLOWS_EXECUTIONS.format(**params_path), |
|
|
data=payload) |
|
|
data=payload) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204]) |
|
|
|
|
|
|
|
|
def sync_users(self, storage_id, action): |
|
|
def sync_users(self, storage_id, action): |
|
|
""" |
|
|
""" |
|
@ -1268,7 +1268,7 @@ class KeycloakAdmin: |
|
|
data_raw = self.raw_post( |
|
|
data_raw = self.raw_post( |
|
|
URL_ADMIN_CLIENT_SCOPES_ADD_MAPPER.format(**params_path), data=json.dumps(payload)) |
|
|
URL_ADMIN_CLIENT_SCOPES_ADD_MAPPER.format(**params_path), data=json.dumps(payload)) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=201) |
|
|
|
|
|
|
|
|
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201]) |
|
|
|
|
|
|
|
|
def generate_client_secrets(self, client_id): |
|
|
def generate_client_secrets(self, client_id): |
|
|
""" |
|
|
""" |
|
|