diff --git a/keycloak/keycloak_admin.py b/keycloak/keycloak_admin.py index fce82ef..dadf11b 100644 --- a/keycloak/keycloak_admin.py +++ b/keycloak/keycloak_admin.py @@ -114,6 +114,22 @@ class KeycloakAdmin: def token(self, value): self._token = value + def import_realm(self, payload): + """ + Import a new realm from a RealmRepresentation. Realm name must be unique. + + RealmRepresentation + https://www.keycloak.org/docs-api/4.4/rest-api/index.html#_realmrepresentation + + :param payload: RealmRepresentation + + :return: RealmRepresentation + """ + + data_raw = self.connection.raw_post(URL_ADMIN_REALM_IMPORT, + data=json.dumps(payload)) + return raise_error_from_response(data_raw, KeycloakGetError, expected_code=201) + def get_users(self, query=None): """ Get users Returns a list of users, filtered according to query parameters diff --git a/keycloak/urls_patterns.py b/keycloak/urls_patterns.py index 4b79bfd..8746fda 100644 --- a/keycloak/urls_patterns.py +++ b/keycloak/urls_patterns.py @@ -64,6 +64,7 @@ URL_ADMIN_CLIENT_AUTHZ_RESOURCES = "admin/realms/{realm-name}/clients/{id}/authz URL_ADMIN_CLIENT_CERTS = "admin/realms/{realm-name}/clients/{id}/certificates/{attr}" URL_ADMIN_REALM_ROLES = "admin/realms/{realm-name}/roles" +URL_ADMIN_REALM_IMPORT = "admin/realms" URL_ADMIN_IDPS = "admin/realms/{realm-name}/identity-provider/instances" URL_ADMIN_FLOWS = "admin/realms/{realm-name}/authentication/flows"