diff --git a/src/keycloak/keycloak_admin.py b/src/keycloak/keycloak_admin.py index bb93f6a..6fa7f12 100644 --- a/src/keycloak/keycloak_admin.py +++ b/src/keycloak/keycloak_admin.py @@ -150,7 +150,8 @@ class KeycloakAdmin: custom_headers=custom_headers, timeout=timeout, ) - self.auto_refresh_token = auto_refresh_token + if auto_refresh_token is not None: + self.auto_refresh_token = auto_refresh_token @property @deprecation.deprecated( @@ -546,7 +547,7 @@ class KeycloakAdmin: :rtype: dict """ params_path = { - "realm-name": self.realm_name, + "realm-name": self.connection.realm_name, "export-clients": export_clients, "export-groups-and-roles": export_groups_and_role, } @@ -647,7 +648,7 @@ class KeycloakAdmin: :rtype: list """ query = query or {} - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} url = urls_patterns.URL_ADMIN_USERS.format(**params_path) if "first" in query or "max" in query: @@ -666,7 +667,7 @@ class KeycloakAdmin: :returns: Keycloak server response :rtype: dict """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_IDPS.format(**params_path), data=json.dumps(payload) ) @@ -685,7 +686,7 @@ class KeycloakAdmin: :returns: Keycloak server response :rtype: dict """ - params_path = {"realm-name": self.realm_name, "alias": idp_alias} + params_path = {"realm-name": self.connection.realm_name, "alias": idp_alias} data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_IDP.format(**params_path), data=json.dumps(payload) ) @@ -704,7 +705,7 @@ class KeycloakAdmin: :returns: Keycloak server response :rtype: dict """ - params_path = {"realm-name": self.realm_name, "idp-alias": idp_alias} + params_path = {"realm-name": self.connection.realm_name, "idp-alias": idp_alias} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_IDP_MAPPERS.format(**params_path), data=json.dumps(payload) ) @@ -726,7 +727,7 @@ class KeycloakAdmin: :rtype: dict """ params_path = { - "realm-name": self.realm_name, + "realm-name": self.connection.realm_name, "idp-alias": idp_alias, "mapper-id": mapper_id, } @@ -751,7 +752,7 @@ class KeycloakAdmin: :return: array IdentityProviderMapperRepresentation :rtype: list """ - params_path = {"realm-name": self.realm_name, "idp-alias": idp_alias} + params_path = {"realm-name": self.connection.realm_name, "idp-alias": idp_alias} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_IDP_MAPPERS.format(**params_path) ) @@ -768,7 +769,7 @@ class KeycloakAdmin: :return: array IdentityProviderRepresentation :rtype: list """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_get(urls_patterns.URL_ADMIN_IDPS.format(**params_path)) return raise_error_from_response(data_raw, KeycloakGetError) @@ -780,7 +781,7 @@ class KeycloakAdmin: :returns: Keycloak server response :rtype: dict """ - params_path = {"realm-name": self.realm_name, "alias": idp_alias} + params_path = {"realm-name": self.connection.realm_name, "alias": idp_alias} data_raw = self.connection.raw_delete(urls_patterns.URL_ADMIN_IDP.format(**params_path)) return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204]) @@ -801,7 +802,7 @@ class KeycloakAdmin: :return: UserRepresentation :rtype: dict """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} if exist_ok: exists = self.get_user_id(username=payload["username"]) @@ -828,7 +829,7 @@ class KeycloakAdmin: :rtype: int """ query = query or dict() - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_USERS_COUNT.format(**params_path), **query ) @@ -862,7 +863,7 @@ class KeycloakAdmin: :type user_id: str :return: UserRepresentation """ - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} data_raw = self.connection.raw_get(urls_patterns.URL_ADMIN_USER.format(**params_path)) return raise_error_from_response(data_raw, KeycloakGetError) @@ -879,7 +880,7 @@ class KeycloakAdmin: :rtype: list """ params = {"briefRepresentation": brief_representation} - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_USER_GROUPS.format(**params_path), **params ) @@ -896,7 +897,7 @@ class KeycloakAdmin: :return: Http response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_USER.format(**params_path), data=json.dumps(payload) ) @@ -946,7 +947,7 @@ class KeycloakAdmin: :return: Http response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} data_raw = self.connection.raw_delete(urls_patterns.URL_ADMIN_USER.format(**params_path)) return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204]) @@ -969,7 +970,7 @@ class KeycloakAdmin: :rtype: dict """ payload = {"type": "password", "temporary": temporary, "value": password} - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_RESET_PASSWORD.format(**params_path), data=json.dumps(payload) ) @@ -988,7 +989,7 @@ class KeycloakAdmin: :returns: Keycloak server response (CredentialRepresentation) :rtype: dict """ - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_USER_CREDENTIALS.format(**params_path) ) @@ -1008,7 +1009,7 @@ class KeycloakAdmin: :rtype: bytes """ params_path = { - "realm-name": self.realm_name, + "realm-name": self.connection.realm_name, "id": user_id, "credential_id": credential_id, } @@ -1027,7 +1028,7 @@ class KeycloakAdmin: :returns: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_USER_LOGOUT.format(**params_path), data="" ) @@ -1044,7 +1045,7 @@ class KeycloakAdmin: :returns: List of UserConsentRepresentations :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_USER_CONSENTS.format(**params_path) ) @@ -1060,7 +1061,7 @@ class KeycloakAdmin: :returns: Federated identities list :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_USER_FEDERATED_IDENTITIES.format(**params_path) ) @@ -1085,7 +1086,11 @@ class KeycloakAdmin: "userId": provider_userid, "userName": provider_username, } - params_path = {"realm-name": self.realm_name, "id": user_id, "provider": provider_id} + params_path = { + "realm-name": self.connection.realm_name, + "id": user_id, + "provider": provider_id, + } data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_USER_FEDERATED_IDENTITY.format(**params_path), data=json.dumps(payload), @@ -1102,7 +1107,11 @@ class KeycloakAdmin: :returns: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": user_id, "provider": provider_id} + params_path = { + "realm-name": self.connection.realm_name, + "id": user_id, + "provider": provider_id, + } data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_USER_FEDERATED_IDENTITY.format(**params_path) ) @@ -1129,7 +1138,7 @@ class KeycloakAdmin: :returns: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} params_query = {"client_id": client_id, "lifespan": lifespan, "redirect_uri": redirect_uri} data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_SEND_UPDATE_ACCOUNT.format(**params_path), @@ -1153,7 +1162,7 @@ class KeycloakAdmin: :returns: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} params_query = {"client_id": client_id, "redirect_uri": redirect_uri} data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_SEND_VERIFY_EMAIL.format(**params_path), @@ -1173,7 +1182,7 @@ class KeycloakAdmin: :return: UserSessionRepresentation :rtype: dict """ - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_GET_SESSIONS.format(**params_path) ) @@ -1205,7 +1214,7 @@ class KeycloakAdmin: :rtype: list """ query = query or {} - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} url = urls_patterns.URL_ADMIN_GROUPS.format(**params_path) if "first" in query or "max" in query: @@ -1226,7 +1235,7 @@ class KeycloakAdmin: :return: Keycloak server response (GroupRepresentation) :rtype: dict """ - params_path = {"realm-name": self.realm_name, "id": group_id} + params_path = {"realm-name": self.connection.realm_name, "id": group_id} data_raw = self.connection.raw_get(urls_patterns.URL_ADMIN_GROUP.format(**params_path)) return raise_error_from_response(data_raw, KeycloakGetError) @@ -1273,7 +1282,7 @@ class KeycloakAdmin: :rtype: list """ query = query or {} - params_path = {"realm-name": self.realm_name, "id": group_id} + params_path = {"realm-name": self.connection.realm_name, "id": group_id} url = urls_patterns.URL_ADMIN_GROUP_MEMBERS.format(**params_path) if "first" in query or "max" in query: @@ -1294,7 +1303,7 @@ class KeycloakAdmin: :return: Keycloak server response (GroupRepresentation) :rtype: dict """ - params_path = {"realm-name": self.realm_name, "path": path} + params_path = {"realm-name": self.connection.realm_name, "path": path} data_raw = self.raw_get(urls_patterns.URL_ADMIN_GROUP_BY_PATH.format(**params_path)) return raise_error_from_response(data_raw, KeycloakGetError) @@ -1315,12 +1324,12 @@ class KeycloakAdmin: :rtype: str """ if parent is None: - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_GROUPS.format(**params_path), data=json.dumps(payload) ) else: - params_path = {"realm-name": self.realm_name, "id": parent} + params_path = {"realm-name": self.connection.realm_name, "id": parent} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_GROUP_CHILD.format(**params_path), data=json.dumps(payload) ) @@ -1348,7 +1357,7 @@ class KeycloakAdmin: :return: Http response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": group_id} + params_path = {"realm-name": self.connection.realm_name, "id": group_id} data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_GROUP.format(**params_path), data=json.dumps(payload) ) @@ -1366,7 +1375,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": group_id} + params_path = {"realm-name": self.connection.realm_name, "id": group_id} data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_GROUP_PERMISSIONS.format(**params_path), data=json.dumps({"enabled": enabled}), @@ -1383,7 +1392,11 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": user_id, "group-id": group_id} + params_path = { + "realm-name": self.connection.realm_name, + "id": user_id, + "group-id": group_id, + } data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_USER_GROUP.format(**params_path), data=None ) @@ -1399,7 +1412,11 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": user_id, "group-id": group_id} + params_path = { + "realm-name": self.connection.realm_name, + "id": user_id, + "group-id": group_id, + } data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_USER_GROUP.format(**params_path) ) @@ -1413,7 +1430,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": group_id} + params_path = {"realm-name": self.connection.realm_name, "id": group_id} data_raw = self.connection.raw_delete(urls_patterns.URL_ADMIN_GROUP.format(**params_path)) return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204]) @@ -1428,7 +1445,7 @@ class KeycloakAdmin: :return: Keycloak server response (ClientRepresentation) :rtype: list """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_get(urls_patterns.URL_ADMIN_CLIENTS.format(**params_path)) return raise_error_from_response(data_raw, KeycloakGetError) @@ -1443,7 +1460,7 @@ class KeycloakAdmin: :return: Keycloak server response (ClientRepresentation) :rtype: dict """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_get(urls_patterns.URL_ADMIN_CLIENT.format(**params_path)) return raise_error_from_response(data_raw, KeycloakGetError) @@ -1475,7 +1492,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: dict """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_AUTHZ_SETTINGS.format(**params_path) ) @@ -1496,7 +1513,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_CLIENT_AUTHZ_RESOURCES.format(**params_path), @@ -1515,7 +1532,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: dict """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_AUTHZ_RESOURCES.format(**params_path) ) @@ -1549,7 +1566,7 @@ class KeycloakAdmin: :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_CLIENT_AUTHZ_ROLE_BASED_POLICY.format(**params_path), @@ -1588,7 +1605,7 @@ class KeycloakAdmin: :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_CLIENT_AUTHZ_RESOURCE_BASED_PERMISSION.format(**params_path), @@ -1607,7 +1624,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_AUTHZ_SCOPES.format(**params_path) ) @@ -1625,7 +1642,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_CLIENT_AUTHZ_SCOPES.format(**params_path), data=json.dumps(payload), @@ -1641,7 +1658,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_AUTHZ_PERMISSIONS.format(**params_path) ) @@ -1656,7 +1673,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_AUTHZ_POLICIES.format(**params_path) ) @@ -1674,7 +1691,11 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: dict """ - params_path = {"realm-name": self.realm_name, "id": client_id, "policy-id": policy_id} + params_path = { + "realm-name": self.connection.realm_name, + "id": client_id, + "policy-id": policy_id, + } data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_CLIENT_AUTHZ_POLICY.format(**params_path) ) @@ -1692,7 +1713,11 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: dict """ - params_path = {"realm-name": self.realm_name, "id": client_id, "policy-id": policy_id} + params_path = { + "realm-name": self.connection.realm_name, + "id": client_id, + "policy-id": policy_id, + } data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_AUTHZ_POLICY.format(**params_path) ) @@ -1707,7 +1732,7 @@ class KeycloakAdmin: :return: UserRepresentation :rtype: dict """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_SERVICE_ACCOUNT_USER.format(**params_path) ) @@ -1722,7 +1747,7 @@ class KeycloakAdmin: :return: list of client scopes with id and name :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_DEFAULT_CLIENT_SCOPES.format(**params_path) ) @@ -1750,7 +1775,7 @@ class KeycloakAdmin: :rtype: bytes """ params_path = { - "realm-name": self.realm_name, + "realm-name": self.connection.realm_name, "id": client_id, "client_scope_id": client_scope_id, } @@ -1772,7 +1797,7 @@ class KeycloakAdmin: :rtype: list """ params_path = { - "realm-name": self.realm_name, + "realm-name": self.connection.realm_name, "id": client_id, "client_scope_id": client_scope_id, } @@ -1790,7 +1815,7 @@ class KeycloakAdmin: :return: list of client scopes with id and name :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_OPTIONAL_CLIENT_SCOPES.format(**params_path) ) @@ -1818,7 +1843,7 @@ class KeycloakAdmin: :rtype: bytes """ params_path = { - "realm-name": self.realm_name, + "realm-name": self.connection.realm_name, "id": client_id, "client_scope_id": client_scope_id, } @@ -1840,7 +1865,7 @@ class KeycloakAdmin: :rtype: list """ params_path = { - "realm-name": self.realm_name, + "realm-name": self.connection.realm_name, "id": client_id, "client_scope_id": client_scope_id, } @@ -1860,7 +1885,7 @@ class KeycloakAdmin: :rtype: str """ payload = {"count": count, "expiration": expiration} - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_CLIENT_INITIAL_ACCESS.format(**params_path), data=json.dumps(payload), @@ -1886,7 +1911,7 @@ class KeycloakAdmin: if client_id is not None: return client_id - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_CLIENTS.format(**params_path), data=json.dumps(payload) ) @@ -1907,7 +1932,7 @@ class KeycloakAdmin: :return: Http response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_CLIENT.format(**params_path), data=json.dumps(payload) ) @@ -1924,7 +1949,7 @@ class KeycloakAdmin: :return: Keycloak server response (ClientRepresentation) :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_delete(urls_patterns.URL_ADMIN_CLIENT.format(**params_path)) return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204]) @@ -1944,7 +1969,11 @@ class KeycloakAdmin: :returns: Installation providers :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": client_id, "provider-id": provider_id} + params_path = { + "realm-name": self.connection.realm_name, + "id": client_id, + "provider-id": provider_id, + } data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_INSTALLATION_PROVIDER.format(**params_path) ) @@ -1961,7 +1990,7 @@ class KeycloakAdmin: :return: Keycloak server response (RoleRepresentation) :rtype: list """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} params = {"briefRepresentation": brief_representation} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_REALM_ROLES.format(**params_path), **params @@ -1980,7 +2009,7 @@ class KeycloakAdmin: :rtype: list """ query = query or dict() - params_path = {"realm-name": self.realm_name, "role-name": role_name} + params_path = {"realm-name": self.connection.realm_name, "role-name": role_name} return self.__fetch_all( urls_patterns.URL_ADMIN_REALM_ROLES_MEMBERS.format(**params_path), query ) @@ -1995,7 +2024,7 @@ class KeycloakAdmin: default_realm_roles = [ realm_role for realm_role in all_realm_roles - if realm_role["name"] == f"default-roles-{self.realm_name}" + if realm_role["name"] == f"default-roles-{self.connection.realm_name}" ] return default_realm_roles[0]["id"] @@ -2005,7 +2034,10 @@ class KeycloakAdmin: :return: Keycloak Server Response (UserRepresentation) :rtype: list """ - params_path = {"realm-name": self.realm_name, "role-id": self.get_default_realm_role_id()} + params_path = { + "realm-name": self.connection.realm_name, + "role-id": self.get_default_realm_role_id(), + } data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_REALM_ROLE_COMPOSITES_REALM.format(**params_path) ) @@ -2019,7 +2051,10 @@ class KeycloakAdmin: :return: Keycloak Server Response :rtype: dict """ - params_path = {"realm-name": self.realm_name, "role-id": self.get_default_realm_role_id()} + params_path = { + "realm-name": self.connection.realm_name, + "role-id": self.get_default_realm_role_id(), + } data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_REALM_ROLE_COMPOSITES.format(**params_path), data=json.dumps(payload), @@ -2034,7 +2069,10 @@ class KeycloakAdmin: :return: Keycloak Server Response :rtype: dict """ - params_path = {"realm-name": self.realm_name, "role-id": self.get_default_realm_role_id()} + params_path = { + "realm-name": self.connection.realm_name, + "role-id": self.get_default_realm_role_id(), + } data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_REALM_ROLE_COMPOSITES.format(**params_path), data=json.dumps(payload), @@ -2054,7 +2092,7 @@ class KeycloakAdmin: :return: Keycloak server response (RoleRepresentation) :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} params = {"briefRepresentation": brief_representation} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_ROLES.format(**params_path), **params @@ -2076,7 +2114,11 @@ class KeycloakAdmin: :return: role_id :rtype: str """ - params_path = {"realm-name": self.realm_name, "id": client_id, "role-name": role_name} + params_path = { + "realm-name": self.connection.realm_name, + "id": client_id, + "role-name": role_name, + } data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_ROLE.format(**params_path) ) @@ -2122,7 +2164,7 @@ class KeycloakAdmin: except KeycloakGetError: pass - params_path = {"realm-name": self.realm_name, "id": client_role_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_role_id} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_CLIENT_ROLES.format(**params_path), data=json.dumps(payload) ) @@ -2145,7 +2187,11 @@ class KeycloakAdmin: :rtype: bytes """ payload = roles if isinstance(roles, list) else [roles] - params_path = {"realm-name": self.realm_name, "id": client_role_id, "role-name": role_name} + params_path = { + "realm-name": self.connection.realm_name, + "id": client_role_id, + "role-name": role_name, + } data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_CLIENT_ROLES_COMPOSITE_CLIENT_ROLE.format(**params_path), data=json.dumps(payload), @@ -2167,7 +2213,11 @@ class KeycloakAdmin: :returns: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": client_role_id, "role-name": role_name} + params_path = { + "realm-name": self.connection.realm_name, + "id": client_role_id, + "role-name": role_name, + } data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_CLIENT_ROLE.format(**params_path), data=json.dumps(payload) ) @@ -2186,7 +2236,11 @@ class KeycloakAdmin: :returns: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": client_role_id, "role-name": role_name} + params_path = { + "realm-name": self.connection.realm_name, + "id": client_role_id, + "role-name": role_name, + } data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_CLIENT_ROLE.format(**params_path) ) @@ -2205,7 +2259,11 @@ class KeycloakAdmin: :rtype: bytes """ payload = roles if isinstance(roles, list) else [roles] - params_path = {"realm-name": self.realm_name, "id": user_id, "client-id": client_id} + params_path = { + "realm-name": self.connection.realm_name, + "id": user_id, + "client-id": client_id, + } data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_USER_CLIENT_ROLES.format(**params_path), data=json.dumps(payload), @@ -2225,7 +2283,11 @@ class KeycloakAdmin: :return: Keycloak server response (UserRepresentation) :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": client_id, "role-name": role_name} + params_path = { + "realm-name": self.connection.realm_name, + "id": client_id, + "role-name": role_name, + } return self.__fetch_all( urls_patterns.URL_ADMIN_CLIENT_ROLE_MEMBERS.format(**params_path), query ) @@ -2243,7 +2305,11 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": client_id, "role-name": role_name} + params_path = { + "realm-name": self.connection.realm_name, + "id": client_id, + "role-name": role_name, + } return self.__fetch_all( urls_patterns.URL_ADMIN_CLIENT_ROLE_GROUPS.format(**params_path), query ) @@ -2265,7 +2331,7 @@ class KeycloakAdmin: except KeycloakGetError: pass - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_REALM_ROLES.format(**params_path), data=json.dumps(payload) ) @@ -2286,7 +2352,7 @@ class KeycloakAdmin: :return: role :rtype: dict """ - params_path = {"realm-name": self.realm_name, "role-name": role_name} + params_path = {"realm-name": self.connection.realm_name, "role-name": role_name} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_REALM_ROLES_ROLE_BY_NAME.format(**params_path) ) @@ -2302,7 +2368,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "role-name": role_name} + params_path = {"realm-name": self.connection.realm_name, "role-name": role_name} data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_REALM_ROLES_ROLE_BY_NAME.format(**params_path), data=json.dumps(payload), @@ -2317,7 +2383,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "role-name": role_name} + params_path = {"realm-name": self.connection.realm_name, "role-name": role_name} data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_REALM_ROLES_ROLE_BY_NAME.format(**params_path) ) @@ -2334,7 +2400,7 @@ class KeycloakAdmin: :rtype: bytes """ payload = roles if isinstance(roles, list) else [roles] - params_path = {"realm-name": self.realm_name, "role-name": role_name} + params_path = {"realm-name": self.connection.realm_name, "role-name": role_name} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_REALM_ROLES_COMPOSITE_REALM_ROLE.format(**params_path), data=json.dumps(payload), @@ -2352,7 +2418,7 @@ class KeycloakAdmin: :rtype: bytes """ payload = roles if isinstance(roles, list) else [roles] - params_path = {"realm-name": self.realm_name, "role-name": role_name} + params_path = {"realm-name": self.connection.realm_name, "role-name": role_name} data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_REALM_ROLES_COMPOSITE_REALM_ROLE.format(**params_path), data=json.dumps(payload), @@ -2367,7 +2433,7 @@ class KeycloakAdmin: :return: Keycloak server response (array RoleRepresentation) :rtype: list """ - params_path = {"realm-name": self.realm_name, "role-name": role_name} + params_path = {"realm-name": self.connection.realm_name, "role-name": role_name} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_REALM_ROLES_COMPOSITE_REALM_ROLE.format(**params_path) ) @@ -2384,7 +2450,7 @@ class KeycloakAdmin: :rtype: dict """ payload = roles if isinstance(roles, list) else [roles] - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_CLIENT_SCOPE_MAPPINGS_REALM_ROLES.format(**params_path), data=json.dumps(payload), @@ -2402,7 +2468,7 @@ class KeycloakAdmin: :rtype: dict """ payload = roles if isinstance(roles, list) else [roles] - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_CLIENT_SCOPE_MAPPINGS_REALM_ROLES.format(**params_path), data=json.dumps(payload), @@ -2417,7 +2483,7 @@ class KeycloakAdmin: :return: Keycloak server response (array RoleRepresentation) :rtype: dict """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_SCOPE_MAPPINGS_REALM_ROLES.format(**params_path) ) @@ -2437,7 +2503,7 @@ class KeycloakAdmin: """ payload = roles if isinstance(roles, list) else [roles] params_path = { - "realm-name": self.realm_name, + "realm-name": self.connection.realm_name, "id": client_id, "client": client_roles_owner_id, } @@ -2461,7 +2527,7 @@ class KeycloakAdmin: """ payload = roles if isinstance(roles, list) else [roles] params_path = { - "realm-name": self.realm_name, + "realm-name": self.connection.realm_name, "id": client_id, "client": client_roles_owner_id, } @@ -2482,7 +2548,7 @@ class KeycloakAdmin: :rtype: dict """ params_path = { - "realm-name": self.realm_name, + "realm-name": self.connection.realm_name, "id": client_id, "client": client_roles_owner_id, } @@ -2502,7 +2568,7 @@ class KeycloakAdmin: :rtype: bytes """ payload = roles if isinstance(roles, list) else [roles] - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_USER_REALM_ROLES.format(**params_path), data=json.dumps(payload), @@ -2520,7 +2586,7 @@ class KeycloakAdmin: :rtype: bytes """ payload = roles if isinstance(roles, list) else [roles] - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_USER_REALM_ROLES.format(**params_path), data=json.dumps(payload), @@ -2535,7 +2601,7 @@ class KeycloakAdmin: :return: Keycloak server response (array RoleRepresentation) :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_USER_REALM_ROLES.format(**params_path) ) @@ -2549,7 +2615,7 @@ class KeycloakAdmin: :return: Keycloak server response (array RoleRepresentation) :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_USER_REALM_ROLES_AVAILABLE.format(**params_path) ) @@ -2565,7 +2631,7 @@ class KeycloakAdmin: :return: Keycloak server response (array RoleRepresentation) :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} params = {"briefRepresentation": brief_representation} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_USER_REALM_ROLES_COMPOSITE.format(**params_path), **params @@ -2583,7 +2649,7 @@ class KeycloakAdmin: :rtype: bytes """ payload = roles if isinstance(roles, list) else [roles] - params_path = {"realm-name": self.realm_name, "id": group_id} + params_path = {"realm-name": self.connection.realm_name, "id": group_id} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_GROUPS_REALM_ROLES.format(**params_path), data=json.dumps(payload), @@ -2601,7 +2667,7 @@ class KeycloakAdmin: :rtype: bytes """ payload = roles if isinstance(roles, list) else [roles] - params_path = {"realm-name": self.realm_name, "id": group_id} + params_path = {"realm-name": self.connection.realm_name, "id": group_id} data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_GROUPS_REALM_ROLES.format(**params_path), data=json.dumps(payload), @@ -2618,7 +2684,7 @@ class KeycloakAdmin: :return: Keycloak server response (array RoleRepresentation) :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": group_id} + params_path = {"realm-name": self.connection.realm_name, "id": group_id} params = {"briefRepresentation": brief_representation} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_GROUPS_REALM_ROLES.format(**params_path), **params @@ -2638,7 +2704,11 @@ class KeycloakAdmin: :rtype: bytes """ payload = roles if isinstance(roles, list) else [roles] - params_path = {"realm-name": self.realm_name, "id": group_id, "client-id": client_id} + params_path = { + "realm-name": self.connection.realm_name, + "id": group_id, + "client-id": client_id, + } data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_GROUPS_CLIENT_ROLES.format(**params_path), data=json.dumps(payload), @@ -2655,7 +2725,11 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": group_id, "client-id": client_id} + params_path = { + "realm-name": self.connection.realm_name, + "id": group_id, + "client-id": client_id, + } data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_GROUPS_CLIENT_ROLES.format(**params_path) ) @@ -2674,7 +2748,11 @@ class KeycloakAdmin: :rtype: bytes """ payload = roles if isinstance(roles, list) else [roles] - params_path = {"realm-name": self.realm_name, "id": group_id, "client-id": client_id} + params_path = { + "realm-name": self.connection.realm_name, + "id": group_id, + "client-id": client_id, + } data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_GROUPS_CLIENT_ROLES.format(**params_path), data=json.dumps(payload), @@ -2742,7 +2820,11 @@ class KeycloakAdmin: :returns: Client roles of a user :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": user_id, "client-id": client_id} + params_path = { + "realm-name": self.connection.realm_name, + "id": user_id, + "client-id": client_id, + } data_raw = self.connection.raw_get( client_level_role_mapping_url.format(**params_path), **params ) @@ -2761,7 +2843,11 @@ class KeycloakAdmin: :rtype: bytes """ payload = roles if isinstance(roles, list) else [roles] - params_path = {"realm-name": self.realm_name, "id": user_id, "client-id": client_id} + params_path = { + "realm-name": self.connection.realm_name, + "id": user_id, + "client-id": client_id, + } data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_USER_CLIENT_ROLES.format(**params_path), data=json.dumps(payload), @@ -2779,7 +2865,7 @@ class KeycloakAdmin: :return: Keycloak server response (AuthenticationFlowRepresentation) :rtype: list """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_get(urls_patterns.URL_ADMIN_FLOWS.format(**params_path)) return raise_error_from_response(data_raw, KeycloakGetError) @@ -2796,7 +2882,7 @@ class KeycloakAdmin: :return: Keycloak server response (AuthenticationFlowRepresentation) :rtype: dict """ - params_path = {"realm-name": self.realm_name, "flow-id": flow_id} + params_path = {"realm-name": self.connection.realm_name, "flow-id": flow_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_FLOWS_ALIAS.format(**params_path) ) @@ -2815,7 +2901,7 @@ class KeycloakAdmin: :return: Keycloak server response (RoleRepresentation) :rtype: bytes """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_FLOWS.format(**params_path), data=json.dumps(payload) ) @@ -2835,7 +2921,7 @@ class KeycloakAdmin: :return: Keycloak server response (RoleRepresentation) :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "flow-alias": flow_alias} + params_path = {"realm-name": self.connection.realm_name, "flow-alias": flow_alias} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_FLOWS_COPY.format(**params_path), data=json.dumps(payload) ) @@ -2852,7 +2938,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": flow_id} + params_path = {"realm-name": self.connection.realm_name, "id": flow_id} data_raw = self.connection.raw_delete(urls_patterns.URL_ADMIN_FLOW.format(**params_path)) return raise_error_from_response(data_raw, KeycloakDeleteError, expected_codes=[204]) @@ -2866,7 +2952,7 @@ class KeycloakAdmin: :return: Response(json) :rtype: list """ - params_path = {"realm-name": self.realm_name, "flow-alias": flow_alias} + params_path = {"realm-name": self.connection.realm_name, "flow-alias": flow_alias} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_FLOWS_EXECUTIONS.format(**params_path) ) @@ -2885,7 +2971,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "flow-alias": flow_alias} + params_path = {"realm-name": self.connection.realm_name, "flow-alias": flow_alias} data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_FLOWS_EXECUTIONS.format(**params_path), data=json.dumps(payload), @@ -2903,7 +2989,7 @@ class KeycloakAdmin: :return: Response(json) :rtype: dict """ - params_path = {"realm-name": self.realm_name, "id": execution_id} + params_path = {"realm-name": self.connection.realm_name, "id": execution_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_FLOWS_EXECUTION.format(**params_path) ) @@ -2922,7 +3008,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "flow-alias": flow_alias} + params_path = {"realm-name": self.connection.realm_name, "flow-alias": flow_alias} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_FLOWS_EXECUTIONS_EXECUTION.format(**params_path), data=json.dumps(payload), @@ -2940,7 +3026,7 @@ class KeycloakAdmin: :return: Keycloak server response (json) :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": execution_id} + params_path = {"realm-name": self.connection.realm_name, "id": execution_id} data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_FLOWS_EXECUTION.format(**params_path) ) @@ -2961,7 +3047,7 @@ class KeycloakAdmin: :return: Keycloak server response (RoleRepresentation) :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "flow-alias": flow_alias} + params_path = {"realm-name": self.connection.realm_name, "flow-alias": flow_alias} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_FLOWS_EXECUTIONS_FLOW.format(**params_path), data=json.dumps(payload), @@ -2976,7 +3062,7 @@ class KeycloakAdmin: :return: Authenticator providers :rtype: list """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_AUTHENTICATOR_PROVIDERS.format(**params_path) ) @@ -2993,7 +3079,7 @@ class KeycloakAdmin: :return: AuthenticatorConfigInfoRepresentation :rtype: dict """ - params_path = {"realm-name": self.realm_name, "provider-id": provider_id} + params_path = {"realm-name": self.connection.realm_name, "provider-id": provider_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_AUTHENTICATOR_CONFIG_DESCRIPTION.format(**params_path) ) @@ -3009,7 +3095,7 @@ class KeycloakAdmin: :return: Response(json) :rtype: dict """ - params_path = {"realm-name": self.realm_name, "id": config_id} + params_path = {"realm-name": self.connection.realm_name, "id": config_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_AUTHENTICATOR_CONFIG.format(**params_path) ) @@ -3028,7 +3114,7 @@ class KeycloakAdmin: :return: Response(json) :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": config_id} + params_path = {"realm-name": self.connection.realm_name, "id": config_id} data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_AUTHENTICATOR_CONFIG.format(**params_path), data=json.dumps(payload), @@ -3045,7 +3131,7 @@ class KeycloakAdmin: :return: Keycloak server Response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": config_id} + params_path = {"realm-name": self.connection.realm_name, "id": config_id} data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_AUTHENTICATOR_CONFIG.format(**params_path) ) @@ -3064,7 +3150,7 @@ class KeycloakAdmin: data = {"action": action} params_query = {"action": action} - params_path = {"realm-name": self.realm_name, "id": storage_id} + params_path = {"realm-name": self.connection.realm_name, "id": storage_id} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_USER_STORAGE.format(**params_path), data=json.dumps(data), @@ -3081,7 +3167,7 @@ class KeycloakAdmin: :return: Keycloak server response Array of (ClientScopeRepresentation) :rtype: list """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_SCOPES.format(**params_path) ) @@ -3098,7 +3184,7 @@ class KeycloakAdmin: :return: Keycloak server response (ClientScopeRepresentation) :rtype: dict """ - params_path = {"realm-name": self.realm_name, "scope-id": client_scope_id} + params_path = {"realm-name": self.connection.realm_name, "scope-id": client_scope_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_SCOPE.format(**params_path) ) @@ -3141,7 +3227,7 @@ class KeycloakAdmin: if exists is not None: return exists["id"] - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_CLIENT_SCOPES.format(**params_path), data=json.dumps(payload) ) @@ -3164,7 +3250,7 @@ class KeycloakAdmin: :return: Keycloak server response (ClientScopeRepresentation) :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "scope-id": client_scope_id} + params_path = {"realm-name": self.connection.realm_name, "scope-id": client_scope_id} data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_CLIENT_SCOPE.format(**params_path), data=json.dumps(payload) ) @@ -3181,7 +3267,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "scope-id": client_scope_id} + params_path = {"realm-name": self.connection.realm_name, "scope-id": client_scope_id} data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_CLIENT_SCOPE.format(**params_path) ) @@ -3196,7 +3282,7 @@ class KeycloakAdmin: :returns: Keycloak server response (ProtocolMapperRepresentation) :rtype: list """ - params_path = {"realm-name": self.realm_name, "scope-id": client_scope_id} + params_path = {"realm-name": self.connection.realm_name, "scope-id": client_scope_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_SCOPES_ADD_MAPPER.format(**params_path) ) @@ -3214,7 +3300,7 @@ class KeycloakAdmin: :return: Keycloak server Response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "scope-id": client_scope_id} + params_path = {"realm-name": self.connection.realm_name, "scope-id": client_scope_id} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_CLIENT_SCOPES_ADD_MAPPER.format(**params_path), @@ -3236,7 +3322,7 @@ class KeycloakAdmin: :rtype: bytes """ params_path = { - "realm-name": self.realm_name, + "realm-name": self.connection.realm_name, "scope-id": client_scope_id, "protocol-mapper-id": protocol_mapper_id, } @@ -3262,7 +3348,7 @@ class KeycloakAdmin: :rtype: bytes """ params_path = { - "realm-name": self.realm_name, + "realm-name": self.connection.realm_name, "scope-id": client_scope_id, "protocol-mapper-id": protocol_mapper_id, } @@ -3282,7 +3368,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: list """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_DEFAULT_DEFAULT_CLIENT_SCOPES.format(**params_path) ) @@ -3296,7 +3382,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": scope_id} + params_path = {"realm-name": self.connection.realm_name, "id": scope_id} data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_DEFAULT_DEFAULT_CLIENT_SCOPE.format(**params_path) ) @@ -3310,8 +3396,8 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": scope_id} - payload = {"realm": self.realm_name, "clientScopeId": scope_id} + params_path = {"realm-name": self.connection.realm_name, "id": scope_id} + payload = {"realm": self.connection.realm_name, "clientScopeId": scope_id} data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_DEFAULT_DEFAULT_CLIENT_SCOPE.format(**params_path), data=json.dumps(payload), @@ -3326,7 +3412,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: list """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_DEFAULT_OPTIONAL_CLIENT_SCOPES.format(**params_path) ) @@ -3340,7 +3426,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": scope_id} + params_path = {"realm-name": self.connection.realm_name, "id": scope_id} data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_DEFAULT_OPTIONAL_CLIENT_SCOPE.format(**params_path) ) @@ -3354,8 +3440,8 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": scope_id} - payload = {"realm": self.realm_name, "clientScopeId": scope_id} + params_path = {"realm-name": self.connection.realm_name, "id": scope_id} + payload = {"realm": self.connection.realm_name, "clientScopeId": scope_id} data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_DEFAULT_OPTIONAL_CLIENT_SCOPE.format(**params_path), data=json.dumps(payload), @@ -3372,7 +3458,7 @@ class KeycloakAdmin: :returns: KeycloakServerResponse (list of ProtocolMapperRepresentation) :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_PROTOCOL_MAPPERS.format(**params_path) @@ -3392,7 +3478,7 @@ class KeycloakAdmin: :return: Keycloak server Response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_CLIENT_PROTOCOL_MAPPERS.format(**params_path), @@ -3414,7 +3500,7 @@ class KeycloakAdmin: :rtype: bytes """ params_path = { - "realm-name": self.realm_name, + "realm-name": self.connection.realm_name, "id": client_id, "protocol-mapper-id": mapper_id, } @@ -3439,7 +3525,7 @@ class KeycloakAdmin: :rtype: bytes """ params_path = { - "realm-name": self.realm_name, + "realm-name": self.connection.realm_name, "id": client_id, "protocol-mapper-id": client_mapper_id, } @@ -3459,7 +3545,7 @@ class KeycloakAdmin: :return: Keycloak server response (ClientRepresentation) :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_CLIENT_SECRETS.format(**params_path), data=None ) @@ -3475,7 +3561,7 @@ class KeycloakAdmin: :return: Keycloak server response (ClientRepresentation) :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_SECRETS.format(**params_path) ) @@ -3495,7 +3581,7 @@ class KeycloakAdmin: :rtype: list """ query = query or dict() - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_COMPONENTS.format(**params_path), data=None, **query ) @@ -3512,7 +3598,7 @@ class KeycloakAdmin: :return: Component id :rtype: str """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_COMPONENTS.format(**params_path), data=json.dumps(payload) ) @@ -3533,7 +3619,7 @@ class KeycloakAdmin: :return: ComponentRepresentation :rtype: dict """ - params_path = {"realm-name": self.realm_name, "component-id": component_id} + params_path = {"realm-name": self.connection.realm_name, "component-id": component_id} data_raw = self.connection.raw_get(urls_patterns.URL_ADMIN_COMPONENT.format(**params_path)) return raise_error_from_response(data_raw, KeycloakGetError) @@ -3548,7 +3634,7 @@ class KeycloakAdmin: :return: Http response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "component-id": component_id} + params_path = {"realm-name": self.connection.realm_name, "component-id": component_id} data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_COMPONENT.format(**params_path), data=json.dumps(payload) ) @@ -3562,7 +3648,7 @@ class KeycloakAdmin: :return: Http response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "component-id": component_id} + params_path = {"realm-name": self.connection.realm_name, "component-id": component_id} data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_COMPONENT.format(**params_path) ) @@ -3579,7 +3665,7 @@ class KeycloakAdmin: :return: keys list :rtype: list """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_KEYS.format(**params_path), data=None ) @@ -3599,7 +3685,7 @@ class KeycloakAdmin: :rtype: list """ query = query or dict() - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_EVENTS.format(**params_path), data=None, **query ) @@ -3616,7 +3702,7 @@ class KeycloakAdmin: :return: Http response :rtype: bytes """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_EVENTS_CONFIG.format(**params_path), data=json.dumps(payload) ) @@ -3747,7 +3833,7 @@ class KeycloakAdmin: :return: UserSessionRepresentation :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_ALL_SESSIONS.format(**params_path) ) @@ -3761,7 +3847,7 @@ class KeycloakAdmin: :return: Dict of clients and session count :rtype: dict """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_SESSION_STATS.format(**params_path) ) @@ -3776,7 +3862,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_MANAGEMENT_PERMISSIONS.format(**params_path) ) @@ -3802,7 +3888,7 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_CLIENT_MANAGEMENT_PERMISSIONS.format(**params_path), data=json.dumps(payload), @@ -3820,7 +3906,11 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": client_id, "policy-id": policy_id} + params_path = { + "realm-name": self.connection.realm_name, + "id": client_id, + "policy-id": policy_id, + } data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_AUTHZ_POLICY_SCOPES.format(**params_path) ) @@ -3837,7 +3927,11 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": client_id, "policy-id": policy_id} + params_path = { + "realm-name": self.connection.realm_name, + "id": client_id, + "policy-id": policy_id, + } data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_AUTHZ_POLICY_RESOURCES.format(**params_path) ) @@ -3854,7 +3948,11 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": client_id, "scope-id": scope_id} + params_path = { + "realm-name": self.connection.realm_name, + "id": client_id, + "scope-id": scope_id, + } data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_AUTHZ_SCOPE_PERMISSION.format(**params_path) ) @@ -3886,7 +3984,11 @@ class KeycloakAdmin: :return: Keycloak server response :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": client_id, "scope-id": scope_id} + params_path = { + "realm-name": self.connection.realm_name, + "id": client_id, + "scope-id": scope_id, + } data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_CLIENT_AUTHZ_SCOPE_PERMISSION.format(**params_path), data=json.dumps(payload), @@ -3902,7 +4004,7 @@ class KeycloakAdmin: :return: Keycloak server response (RoleRepresentation) :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_AUTHZ_CLIENT_POLICY.format(**params_path) ) @@ -3929,7 +4031,7 @@ class KeycloakAdmin: :return: Keycloak server response (RoleRepresentation) :rtype: bytes """ - params_path = {"realm-name": self.realm_name, "id": client_id} + params_path = {"realm-name": self.connection.realm_name, "id": client_id} data_raw = self.connection.raw_post( urls_patterns.URL_ADMIN_CLIENT_AUTHZ_CLIENT_POLICY.format(**params_path), data=json.dumps(payload), @@ -3948,7 +4050,11 @@ class KeycloakAdmin: :return: the composite client roles of the group (list of RoleRepresentation). :rtype: list """ - params_path = {"realm-name": self.realm_name, "id": group_id, "client-id": client_id} + params_path = { + "realm-name": self.connection.realm_name, + "id": group_id, + "client-id": client_id, + } params = {"briefRepresentation": brief_representation} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_GROUPS_CLIENT_ROLES_COMPOSITE.format(**params_path), **params @@ -3965,7 +4071,11 @@ class KeycloakAdmin: :return: the child roles (list of RoleRepresentation). :rtype: list """ - params_path = {"realm-name": self.realm_name, "role-id": role_id, "client-id": client_id} + params_path = { + "realm-name": self.connection.realm_name, + "role-id": role_id, + "client-id": client_id, + } data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_CLIENT_ROLE_CHILDREN.format(**params_path) ) @@ -3982,7 +4092,11 @@ class KeycloakAdmin: where is the content of the uploaded certificate. :rtype: dict """ - params_path = {"realm-name": self.realm_name, "id": client_id, "attr": "jwt.credential"} + params_path = { + "realm-name": self.connection.realm_name, + "id": client_id, + "attr": "jwt.credential", + } m = MultipartEncoder(fields={"keystoreFormat": "Certificate PEM", "file": certcont}) new_headers = copy.deepcopy(self.connection.headers) new_headers["Content-Type"] = m.content_type @@ -4014,7 +4128,7 @@ class KeycloakAdmin: :return: the required actions (list of RequiredActionProviderRepresentation). :rtype: list """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_REQUIRED_ACTIONS.format(**params_path) ) @@ -4032,7 +4146,7 @@ class KeycloakAdmin: """ if not isinstance(payload, str): payload = json.dumps(payload) - params_path = {"realm-name": self.realm_name, "action-alias": action_alias} + params_path = {"realm-name": self.connection.realm_name, "action-alias": action_alias} data_raw = self.connection.raw_put( urls_patterns.URL_ADMIN_REQUIRED_ACTIONS_ALIAS.format(**params_path), data=payload ) @@ -4046,7 +4160,7 @@ class KeycloakAdmin: :return: Bruteforce status. :rtype: dict """ - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} data_raw = self.connection.raw_get( urls_patterns.URL_ADMIN_ATTACK_DETECTION_USER.format(**params_path) ) @@ -4060,7 +4174,7 @@ class KeycloakAdmin: :return: empty dictionary. :rtype: dict """ - params_path = {"realm-name": self.realm_name, "id": user_id} + params_path = {"realm-name": self.connection.realm_name, "id": user_id} data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_ATTACK_DETECTION_USER.format(**params_path) ) @@ -4072,7 +4186,7 @@ class KeycloakAdmin: :return: empty dictionary. :rtype: dict """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.connection.raw_delete( urls_patterns.URL_ADMIN_ATTACK_DETECTION.format(**params_path) ) @@ -4084,7 +4198,7 @@ class KeycloakAdmin: :return: empty dictionary. :rtype: dict """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.raw_post( urls_patterns.URL_ADMIN_CLEAR_KEYS_CACHE.format(**params_path), data="" ) @@ -4096,7 +4210,7 @@ class KeycloakAdmin: :return: empty dictionary. :rtype: dict """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.raw_post( urls_patterns.URL_ADMIN_CLEAR_REALM_CACHE.format(**params_path), data="" ) @@ -4108,7 +4222,7 @@ class KeycloakAdmin: :return: empty dictionary. :rtype: dict """ - params_path = {"realm-name": self.realm_name} + params_path = {"realm-name": self.connection.realm_name} data_raw = self.raw_post( urls_patterns.URL_ADMIN_CLEAR_USER_CACHE.format(**params_path), data="" ) diff --git a/tests/test_keycloak_admin.py b/tests/test_keycloak_admin.py index c6957d0..4005013 100644 --- a/tests/test_keycloak_admin.py +++ b/tests/test_keycloak_admin.py @@ -46,7 +46,6 @@ def test_keycloak_admin_init(env): assert admin.password == env.KEYCLOAK_ADMIN_PASSWORD, admin.password assert admin.totp is None, admin.totp assert admin.token is not None, admin.token - assert admin.auto_refresh_token == list(), admin.auto_refresh_token assert admin.user_realm_name is None, admin.user_realm_name assert admin.custom_headers is None, admin.custom_headers assert admin.token