Browse Source

Add support to create a new Realm

hotfix/merge
mattboret 6 years ago
parent
commit
a4a990b7f1
  1. 3
      README.md
  2. 18
      keycloak/keycloak_admin.py

3
README.md

@ -236,4 +236,7 @@ keycloak_admin.assign_client_role(client_id=client_id, user_id=user_id, role_id=
# Get all ID Providers # Get all ID Providers
idps = keycloak_admin.get_idps() idps = keycloak_admin.get_idps()
# Create a new Realm
keycloak_admin.create_realm(payload={"realm": "demo", skip_exists=False)
``` ```

18
keycloak/keycloak_admin.py

@ -145,6 +145,22 @@ class KeycloakAdmin:
data_raw = self.connection.raw_get(URL_ADMIN_REALMS) data_raw = self.connection.raw_get(URL_ADMIN_REALMS)
return raise_error_from_response(data_raw, KeycloakGetError) return raise_error_from_response(data_raw, KeycloakGetError)
def create_realm(self, payload, skip_exists=False):
"""
Create a client
ClientRepresentation: http://www.keycloak.org/docs-api/3.3/rest-api/index.html#_realmrepresentation
:param skip_exists: Skip if Realm already exist.
:param payload: RealmRepresentation
:return: Keycloak server response (UserRepresentation)
"""
data_raw = self.connection.raw_post(URL_ADMIN_REALMS,
data=json.dumps(payload))
return raise_error_from_response(data_raw, KeycloakGetError, expected_code=201, skip_exists=skip_exists)
def get_users(self, query=None): def get_users(self, query=None):
""" """
Get users Returns a list of users, filtered according to query parameters Get users Returns a list of users, filtered according to query parameters
@ -932,4 +948,4 @@ 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.connection.raw_get(URL_ADMIN_CLIENT_SECRETS.format(**params_path)) data_raw = self.connection.raw_get(URL_ADMIN_CLIENT_SECRETS.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError)
return raise_error_from_response(data_raw, KeycloakGetError)
Loading…
Cancel
Save