|
@ -49,19 +49,31 @@ class KeycloakAdmin: |
|
|
"""Keycloak Admin client. |
|
|
"""Keycloak Admin client. |
|
|
|
|
|
|
|
|
:param server_url: Keycloak server url |
|
|
:param server_url: Keycloak server url |
|
|
|
|
|
:type server_url: str |
|
|
:param username: admin username |
|
|
:param username: admin username |
|
|
|
|
|
:type username: str |
|
|
:param password: admin password |
|
|
:param password: admin password |
|
|
|
|
|
:type password: str |
|
|
:param totp: Time based OTP |
|
|
:param totp: Time based OTP |
|
|
|
|
|
:type totp: str |
|
|
:param realm_name: realm name |
|
|
:param realm_name: realm name |
|
|
|
|
|
:type realm_name: str |
|
|
:param client_id: client id |
|
|
:param client_id: client id |
|
|
|
|
|
:type client_id: str |
|
|
:param verify: True if want check connection SSL |
|
|
:param verify: True if want check connection SSL |
|
|
|
|
|
:type verify: bool |
|
|
:param client_secret_key: client secret key |
|
|
:param client_secret_key: client secret key |
|
|
(optional, required only for access type confidential) |
|
|
(optional, required only for access type confidential) |
|
|
|
|
|
:type client_secret_key: str |
|
|
:param custom_headers: dict of custom header to pass to each HTML request |
|
|
:param custom_headers: dict of custom header to pass to each HTML request |
|
|
|
|
|
:type custom_headers: dict |
|
|
:param user_realm_name: The realm name of the user, if different from realm_name |
|
|
:param user_realm_name: The realm name of the user, if different from realm_name |
|
|
|
|
|
:type user_realm_name: str |
|
|
:param auto_refresh_token: list of methods that allows automatic token refresh. |
|
|
:param auto_refresh_token: list of methods that allows automatic token refresh. |
|
|
Ex: ['get', 'put', 'post', 'delete'] |
|
|
Ex: ['get', 'put', 'post', 'delete'] |
|
|
|
|
|
:type auto_refresh_token: list |
|
|
:param timeout: connection timeout in seconds |
|
|
:param timeout: connection timeout in seconds |
|
|
|
|
|
:type timeout: int |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
PAGE_SIZE = 100 |
|
|
PAGE_SIZE = 100 |
|
@ -95,7 +107,35 @@ class KeycloakAdmin: |
|
|
auto_refresh_token=None, |
|
|
auto_refresh_token=None, |
|
|
timeout=60, |
|
|
timeout=60, |
|
|
): |
|
|
): |
|
|
"""Init method.""" |
|
|
|
|
|
|
|
|
"""Init method. |
|
|
|
|
|
|
|
|
|
|
|
:param server_url: Keycloak server url |
|
|
|
|
|
:type server_url: str |
|
|
|
|
|
:param username: admin username |
|
|
|
|
|
:type username: str |
|
|
|
|
|
:param password: admin password |
|
|
|
|
|
:type password: str |
|
|
|
|
|
:param totp: Time based OTP |
|
|
|
|
|
:type totp: str |
|
|
|
|
|
:param realm_name: realm name |
|
|
|
|
|
:type realm_name: str |
|
|
|
|
|
:param client_id: client id |
|
|
|
|
|
:type client_id: str |
|
|
|
|
|
:param verify: True if want check connection SSL |
|
|
|
|
|
:type verify: bool |
|
|
|
|
|
:param client_secret_key: client secret key |
|
|
|
|
|
(optional, required only for access type confidential) |
|
|
|
|
|
:type client_secret_key: str |
|
|
|
|
|
:param custom_headers: dict of custom header to pass to each HTML request |
|
|
|
|
|
:type custom_headers: dict |
|
|
|
|
|
:param user_realm_name: The realm name of the user, if different from realm_name |
|
|
|
|
|
:type user_realm_name: str |
|
|
|
|
|
:param auto_refresh_token: list of methods that allows automatic token refresh. |
|
|
|
|
|
Ex: ['get', 'put', 'post', 'delete'] |
|
|
|
|
|
:type auto_refresh_token: list |
|
|
|
|
|
:param timeout: connection timeout in seconds |
|
|
|
|
|
:type timeout: int |
|
|
|
|
|
""" |
|
|
self.server_url = server_url |
|
|
self.server_url = server_url |
|
|
self.username = username |
|
|
self.username = username |
|
|
self.password = password |
|
|
self.password = password |
|
@ -114,7 +154,11 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def server_url(self): |
|
|
def server_url(self): |
|
|
"""Get server url.""" |
|
|
|
|
|
|
|
|
"""Get server url. |
|
|
|
|
|
|
|
|
|
|
|
:returns: Keycloak server url |
|
|
|
|
|
:rtype: str |
|
|
|
|
|
""" |
|
|
return self._server_url |
|
|
return self._server_url |
|
|
|
|
|
|
|
|
@server_url.setter |
|
|
@server_url.setter |
|
@ -123,7 +167,11 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def realm_name(self): |
|
|
def realm_name(self): |
|
|
"""Get realm name.""" |
|
|
|
|
|
|
|
|
"""Get realm name. |
|
|
|
|
|
|
|
|
|
|
|
:returns: Realm name |
|
|
|
|
|
:rtype: str |
|
|
|
|
|
""" |
|
|
return self._realm_name |
|
|
return self._realm_name |
|
|
|
|
|
|
|
|
@realm_name.setter |
|
|
@realm_name.setter |
|
@ -132,7 +180,11 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def connection(self): |
|
|
def connection(self): |
|
|
"""Get connection.""" |
|
|
|
|
|
|
|
|
"""Get connection. |
|
|
|
|
|
|
|
|
|
|
|
:returns: Connection manager |
|
|
|
|
|
:rtype: ConnectionManager |
|
|
|
|
|
""" |
|
|
return self._connection |
|
|
return self._connection |
|
|
|
|
|
|
|
|
@connection.setter |
|
|
@connection.setter |
|
@ -141,7 +193,11 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def client_id(self): |
|
|
def client_id(self): |
|
|
"""Get client id.""" |
|
|
|
|
|
|
|
|
"""Get client id. |
|
|
|
|
|
|
|
|
|
|
|
:returns: Client id |
|
|
|
|
|
:rtype: str |
|
|
|
|
|
""" |
|
|
return self._client_id |
|
|
return self._client_id |
|
|
|
|
|
|
|
|
@client_id.setter |
|
|
@client_id.setter |
|
@ -150,7 +206,11 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def client_secret_key(self): |
|
|
def client_secret_key(self): |
|
|
"""Get client secret key.""" |
|
|
|
|
|
|
|
|
"""Get client secret key. |
|
|
|
|
|
|
|
|
|
|
|
:returns: Client secret key |
|
|
|
|
|
:rtype: str |
|
|
|
|
|
""" |
|
|
return self._client_secret_key |
|
|
return self._client_secret_key |
|
|
|
|
|
|
|
|
@client_secret_key.setter |
|
|
@client_secret_key.setter |
|
@ -159,7 +219,11 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def verify(self): |
|
|
def verify(self): |
|
|
"""Get verify.""" |
|
|
|
|
|
|
|
|
"""Get verify. |
|
|
|
|
|
|
|
|
|
|
|
:returns: Verify indicator |
|
|
|
|
|
:rtype: bool |
|
|
|
|
|
""" |
|
|
return self._verify |
|
|
return self._verify |
|
|
|
|
|
|
|
|
@verify.setter |
|
|
@verify.setter |
|
@ -168,7 +232,11 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def username(self): |
|
|
def username(self): |
|
|
"""Get username.""" |
|
|
|
|
|
|
|
|
"""Get username. |
|
|
|
|
|
|
|
|
|
|
|
:returns: Admin username |
|
|
|
|
|
:rtype: str |
|
|
|
|
|
""" |
|
|
return self._username |
|
|
return self._username |
|
|
|
|
|
|
|
|
@username.setter |
|
|
@username.setter |
|
@ -177,7 +245,11 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def password(self): |
|
|
def password(self): |
|
|
"""Get password.""" |
|
|
|
|
|
|
|
|
"""Get password. |
|
|
|
|
|
|
|
|
|
|
|
:returns: Admin password |
|
|
|
|
|
:rtype: str |
|
|
|
|
|
""" |
|
|
return self._password |
|
|
return self._password |
|
|
|
|
|
|
|
|
@password.setter |
|
|
@password.setter |
|
@ -186,7 +258,11 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def totp(self): |
|
|
def totp(self): |
|
|
"""Get totp.""" |
|
|
|
|
|
|
|
|
"""Get totp. |
|
|
|
|
|
|
|
|
|
|
|
:returns: TOTP |
|
|
|
|
|
:rtype: str |
|
|
|
|
|
""" |
|
|
return self._totp |
|
|
return self._totp |
|
|
|
|
|
|
|
|
@totp.setter |
|
|
@totp.setter |
|
@ -195,7 +271,11 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def token(self): |
|
|
def token(self): |
|
|
"""Get token.""" |
|
|
|
|
|
|
|
|
"""Get token. |
|
|
|
|
|
|
|
|
|
|
|
:returns: Access and refresh token |
|
|
|
|
|
:rtype: dict |
|
|
|
|
|
""" |
|
|
return self._token |
|
|
return self._token |
|
|
|
|
|
|
|
|
@token.setter |
|
|
@token.setter |
|
@ -204,12 +284,20 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def auto_refresh_token(self): |
|
|
def auto_refresh_token(self): |
|
|
"""Get auto refresh token.""" |
|
|
|
|
|
|
|
|
"""Get auto refresh token. |
|
|
|
|
|
|
|
|
|
|
|
:returns: List of methods for automatic token refresh |
|
|
|
|
|
:rtype: list |
|
|
|
|
|
""" |
|
|
return self._auto_refresh_token |
|
|
return self._auto_refresh_token |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def user_realm_name(self): |
|
|
def user_realm_name(self): |
|
|
"""Get user realm name.""" |
|
|
|
|
|
|
|
|
"""Get user realm name. |
|
|
|
|
|
|
|
|
|
|
|
:returns: User realm name |
|
|
|
|
|
:rtype: str |
|
|
|
|
|
""" |
|
|
return self._user_realm_name |
|
|
return self._user_realm_name |
|
|
|
|
|
|
|
|
@user_realm_name.setter |
|
|
@user_realm_name.setter |
|
@ -218,7 +306,11 @@ class KeycloakAdmin: |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def custom_headers(self): |
|
|
def custom_headers(self): |
|
|
"""Get custom headers.""" |
|
|
|
|
|
|
|
|
"""Get custom headers. |
|
|
|
|
|
|
|
|
|
|
|
:returns: Custom headers |
|
|
|
|
|
:rtype: dict |
|
|
|
|
|
""" |
|
|
return self._custom_headers |
|
|
return self._custom_headers |
|
|
|
|
|
|
|
|
@custom_headers.setter |
|
|
@custom_headers.setter |
|
@ -247,13 +339,16 @@ class KeycloakAdmin: |
|
|
Wrapper function to paginate GET requests. |
|
|
Wrapper function to paginate GET requests. |
|
|
|
|
|
|
|
|
:param url: The url on which the query is executed |
|
|
:param url: The url on which the query is executed |
|
|
|
|
|
:type url: str |
|
|
:param query: Existing query parameters (optional) |
|
|
:param query: Existing query parameters (optional) |
|
|
|
|
|
:type query: dict |
|
|
|
|
|
|
|
|
:return: Combined results of paginated queries |
|
|
:return: Combined results of paginated queries |
|
|
|
|
|
:rtype: list |
|
|
""" |
|
|
""" |
|
|
results = [] |
|
|
results = [] |
|
|
|
|
|
|
|
|
# initalize query if it was called with None |
|
|
|
|
|
|
|
|
# initialize query if it was called with None |
|
|
if not query: |
|
|
if not query: |
|
|
query = {} |
|
|
query = {} |
|
|
page = 0 |
|
|
page = 0 |
|
@ -274,8 +369,16 @@ class KeycloakAdmin: |
|
|
return results |
|
|
return results |
|
|
|
|
|
|
|
|
def __fetch_paginated(self, url, query=None): |
|
|
def __fetch_paginated(self, url, query=None): |
|
|
query = query or {} |
|
|
|
|
|
|
|
|
"""Make a specific paginated request. |
|
|
|
|
|
|
|
|
|
|
|
:param url: The url on which the query is executed |
|
|
|
|
|
:type url: str |
|
|
|
|
|
:param query: Pagination settings |
|
|
|
|
|
:type query: dict |
|
|
|
|
|
:returns: Response |
|
|
|
|
|
:rtype: dict |
|
|
|
|
|
""" |
|
|
|
|
|
query = query or {} |
|
|
return raise_error_from_response(self.raw_get(url, **query), KeycloakGetError) |
|
|
return raise_error_from_response(self.raw_get(url, **query), KeycloakGetError) |
|
|
|
|
|
|
|
|
def import_realm(self, payload): |
|
|
def import_realm(self, payload): |
|
@ -287,8 +390,9 @@ class KeycloakAdmin: |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_realmrepresentation |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_realmrepresentation |
|
|
|
|
|
|
|
|
:param payload: RealmRepresentation |
|
|
:param payload: RealmRepresentation |
|
|
|
|
|
|
|
|
|
|
|
:type payload: dict |
|
|
:return: RealmRepresentation |
|
|
:return: RealmRepresentation |
|
|
|
|
|
:rtype: dict |
|
|
""" |
|
|
""" |
|
|
data_raw = self.raw_post(urls_patterns.URL_ADMIN_REALMS, data=json.dumps(payload)) |
|
|
data_raw = self.raw_post(urls_patterns.URL_ADMIN_REALMS, data=json.dumps(payload)) |
|
|
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[201]) |
|
|
return raise_error_from_response(data_raw, KeycloakPostError, expected_codes=[201]) |
|
@ -299,10 +403,13 @@ class KeycloakAdmin: |
|
|
RealmRepresentation |
|
|
RealmRepresentation |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_partialexport |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_partialexport |
|
|
|
|
|
|
|
|
:param export-clients: Skip if not want to export realm clients |
|
|
|
|
|
:param export-groups-and-roles: Skip if not want to export realm groups and roles |
|
|
|
|
|
|
|
|
:param export_clients: Skip if not want to export realm clients |
|
|
|
|
|
:type export_clients: bool |
|
|
|
|
|
:param export_groups_and_role: Skip if not want to export realm groups and roles |
|
|
|
|
|
:type export_groups_and_role: bool |
|
|
|
|
|
|
|
|
:return: realm configurations JSON |
|
|
:return: realm configurations JSON |
|
|
|
|
|
:rtype: dict |
|
|
""" |
|
|
""" |
|
|
params_path = { |
|
|
params_path = { |
|
|
"realm-name": self.realm_name, |
|
|
"realm-name": self.realm_name, |
|
@ -318,6 +425,7 @@ class KeycloakAdmin: |
|
|
"""List all realms in Keycloak deployment. |
|
|
"""List all realms in Keycloak deployment. |
|
|
|
|
|
|
|
|
:return: realms list |
|
|
:return: realms list |
|
|
|
|
|
:rtype: list |
|
|
""" |
|
|
""" |
|
|
data_raw = self.raw_get(urls_patterns.URL_ADMIN_REALMS) |
|
|
data_raw = self.raw_get(urls_patterns.URL_ADMIN_REALMS) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError) |
|
|
return raise_error_from_response(data_raw, KeycloakGetError) |
|
@ -329,7 +437,9 @@ class KeycloakAdmin: |
|
|
https://www.keycloak.org/docs-api/8.0/rest-api/index.html#_realmrepresentation |
|
|
https://www.keycloak.org/docs-api/8.0/rest-api/index.html#_realmrepresentation |
|
|
|
|
|
|
|
|
:param realm_name: Realm name (not the realm id) |
|
|
:param realm_name: Realm name (not the realm id) |
|
|
|
|
|
:type realm_name: str |
|
|
:return: RealmRepresentation |
|
|
:return: RealmRepresentation |
|
|
|
|
|
:rtype: dict |
|
|
""" |
|
|
""" |
|
|
params_path = {"realm-name": realm_name} |
|
|
params_path = {"realm-name": realm_name} |
|
|
data_raw = self.raw_get(urls_patterns.URL_ADMIN_REALM.format(**params_path)) |
|
|
data_raw = self.raw_get(urls_patterns.URL_ADMIN_REALM.format(**params_path)) |
|
@ -342,8 +452,11 @@ class KeycloakAdmin: |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_realmrepresentation |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_realmrepresentation |
|
|
|
|
|
|
|
|
:param payload: RealmRepresentation |
|
|
:param payload: RealmRepresentation |
|
|
|
|
|
:type payload: dict |
|
|
:param skip_exists: Skip if Realm already exist. |
|
|
:param skip_exists: Skip if Realm already exist. |
|
|
|
|
|
:type skip_exists: bool |
|
|
:return: Keycloak server response (RealmRepresentation) |
|
|
:return: Keycloak server response (RealmRepresentation) |
|
|
|
|
|
:rtype: dict |
|
|
""" |
|
|
""" |
|
|
data_raw = self.raw_post(urls_patterns.URL_ADMIN_REALMS, data=json.dumps(payload)) |
|
|
data_raw = self.raw_post(urls_patterns.URL_ADMIN_REALMS, data=json.dumps(payload)) |
|
|
return raise_error_from_response( |
|
|
return raise_error_from_response( |
|
@ -353,15 +466,18 @@ class KeycloakAdmin: |
|
|
def update_realm(self, realm_name, payload): |
|
|
def update_realm(self, realm_name, payload): |
|
|
"""Update a realm. |
|
|
"""Update a realm. |
|
|
|
|
|
|
|
|
This wil only update top level attributes and will ignore any user, |
|
|
|
|
|
|
|
|
This will only update top level attributes and will ignore any user, |
|
|
role, or client information in the payload. |
|
|
role, or client information in the payload. |
|
|
|
|
|
|
|
|
RealmRepresentation: |
|
|
RealmRepresentation: |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_realmrepresentation |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_realmrepresentation |
|
|
|
|
|
|
|
|
:param realm_name: Realm name (not the realm id) |
|
|
:param realm_name: Realm name (not the realm id) |
|
|
|
|
|
:type realm_name: str |
|
|
:param payload: RealmRepresentation |
|
|
:param payload: RealmRepresentation |
|
|
|
|
|
:type payload: dict |
|
|
:return: Http response |
|
|
:return: Http response |
|
|
|
|
|
:rtype: dict |
|
|
""" |
|
|
""" |
|
|
params_path = {"realm-name": realm_name} |
|
|
params_path = {"realm-name": realm_name} |
|
|
data_raw = self.raw_put( |
|
|
data_raw = self.raw_put( |
|
@ -373,7 +489,9 @@ class KeycloakAdmin: |
|
|
"""Delete a realm. |
|
|
"""Delete a realm. |
|
|
|
|
|
|
|
|
:param realm_name: Realm name (not the realm id) |
|
|
:param realm_name: Realm name (not the realm id) |
|
|
|
|
|
:type realm_name: str |
|
|
:return: Http response |
|
|
:return: Http response |
|
|
|
|
|
:rtype: dict |
|
|
""" |
|
|
""" |
|
|
params_path = {"realm-name": realm_name} |
|
|
params_path = {"realm-name": realm_name} |
|
|
data_raw = self.raw_delete(urls_patterns.URL_ADMIN_REALM.format(**params_path)) |
|
|
data_raw = self.raw_delete(urls_patterns.URL_ADMIN_REALM.format(**params_path)) |
|
@ -388,7 +506,9 @@ class KeycloakAdmin: |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_userrepresentation |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_userrepresentation |
|
|
|
|
|
|
|
|
:param query: Query parameters (optional) |
|
|
:param query: Query parameters (optional) |
|
|
|
|
|
:type query: dict |
|
|
:return: users list |
|
|
:return: users list |
|
|
|
|
|
:rtype: list |
|
|
""" |
|
|
""" |
|
|
query = query or {} |
|
|
query = query or {} |
|
|
params_path = {"realm-name": self.realm_name} |
|
|
params_path = {"realm-name": self.realm_name} |
|
@ -406,6 +526,9 @@ class KeycloakAdmin: |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_identityproviderrepresentation |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_identityproviderrepresentation |
|
|
|
|
|
|
|
|
:param: payload: IdentityProviderRepresentation |
|
|
:param: payload: IdentityProviderRepresentation |
|
|
|
|
|
:type payload: dict |
|
|
|
|
|
:returns: Keycloak server response |
|
|
|
|
|
:rtype: dict |
|
|
""" |
|
|
""" |
|
|
params_path = {"realm-name": self.realm_name} |
|
|
params_path = {"realm-name": self.realm_name} |
|
|
data_raw = self.raw_post( |
|
|
data_raw = self.raw_post( |
|
@ -419,8 +542,12 @@ class KeycloakAdmin: |
|
|
IdentityProviderRepresentation |
|
|
IdentityProviderRepresentation |
|
|
https://www.keycloak.org/docs-api/15.0/rest-api/index.html#_identity_providers_resource |
|
|
https://www.keycloak.org/docs-api/15.0/rest-api/index.html#_identity_providers_resource |
|
|
|
|
|
|
|
|
:param: alias: alias for IdP to update |
|
|
|
|
|
|
|
|
:param: idp_alias: alias for IdP to update |
|
|
|
|
|
:type idp_alias: str |
|
|
:param: payload: The IdentityProviderRepresentation |
|
|
:param: payload: The IdentityProviderRepresentation |
|
|
|
|
|
:type payload: dict |
|
|
|
|
|
:returns: Keycloak server response |
|
|
|
|
|
:rtype: dict |
|
|
""" |
|
|
""" |
|
|
params_path = {"realm-name": self.realm_name, "alias": idp_alias} |
|
|
params_path = {"realm-name": self.realm_name, "alias": idp_alias} |
|
|
data_raw = self.raw_put( |
|
|
data_raw = self.raw_put( |
|
@ -435,7 +562,11 @@ class KeycloakAdmin: |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_identityprovidermapperrepresentation |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_identityprovidermapperrepresentation |
|
|
|
|
|
|
|
|
:param: idp_alias: alias for Idp to add mapper in |
|
|
:param: idp_alias: alias for Idp to add mapper in |
|
|
|
|
|
:type idp_alias: str |
|
|
:param: payload: IdentityProviderMapperRepresentation |
|
|
:param: payload: IdentityProviderMapperRepresentation |
|
|
|
|
|
:type payload: dict |
|
|
|
|
|
:returns: Keycloak server response |
|
|
|
|
|
:rtype: dict |
|
|
""" |
|
|
""" |
|
|
params_path = {"realm-name": self.realm_name, "idp-alias": idp_alias} |
|
|
params_path = {"realm-name": self.realm_name, "idp-alias": idp_alias} |
|
|
data_raw = self.raw_post( |
|
|
data_raw = self.raw_post( |
|
@ -450,9 +581,13 @@ class KeycloakAdmin: |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_update |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_update |
|
|
|
|
|
|
|
|
:param: idp_alias: alias for Idp to fetch mappers |
|
|
:param: idp_alias: alias for Idp to fetch mappers |
|
|
|
|
|
:type idp_alias: str |
|
|
:param: mapper_id: Mapper Id to update |
|
|
:param: mapper_id: Mapper Id to update |
|
|
|
|
|
:type mapper_id: str |
|
|
:param: payload: IdentityProviderMapperRepresentation |
|
|
:param: payload: IdentityProviderMapperRepresentation |
|
|
|
|
|
:type payload: dict |
|
|
:return: Http response |
|
|
:return: Http response |
|
|
|
|
|
:rtype: dict |
|
|
""" |
|
|
""" |
|
|
params_path = { |
|
|
params_path = { |
|
|
"realm-name": self.realm_name, |
|
|
"realm-name": self.realm_name, |
|
@ -476,7 +611,9 @@ class KeycloakAdmin: |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_getmappers |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_getmappers |
|
|
|
|
|
|
|
|
:param: idp_alias: alias for Idp to fetch mappers |
|
|
:param: idp_alias: alias for Idp to fetch mappers |
|
|
|
|
|
:type idp_alias: str |
|
|
:return: array IdentityProviderMapperRepresentation |
|
|
:return: array IdentityProviderMapperRepresentation |
|
|
|
|
|
:rtype: list |
|
|
""" |
|
|
""" |
|
|
params_path = {"realm-name": self.realm_name, "idp-alias": idp_alias} |
|
|
params_path = {"realm-name": self.realm_name, "idp-alias": idp_alias} |
|
|
data_raw = self.raw_get(urls_patterns.URL_ADMIN_IDP_MAPPERS.format(**params_path)) |
|
|
data_raw = self.raw_get(urls_patterns.URL_ADMIN_IDP_MAPPERS.format(**params_path)) |
|
@ -491,6 +628,7 @@ class KeycloakAdmin: |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_identityproviderrepresentation |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_identityproviderrepresentation |
|
|
|
|
|
|
|
|
:return: array IdentityProviderRepresentation |
|
|
:return: array IdentityProviderRepresentation |
|
|
|
|
|
:rtype: list |
|
|
""" |
|
|
""" |
|
|
params_path = {"realm-name": self.realm_name} |
|
|
params_path = {"realm-name": self.realm_name} |
|
|
data_raw = self.raw_get(urls_patterns.URL_ADMIN_IDPS.format(**params_path)) |
|
|
data_raw = self.raw_get(urls_patterns.URL_ADMIN_IDPS.format(**params_path)) |
|
@ -500,6 +638,9 @@ class KeycloakAdmin: |
|
|
"""Delete an ID Provider. |
|
|
"""Delete an ID Provider. |
|
|
|
|
|
|
|
|
:param: idp_alias: idp alias name |
|
|
:param: idp_alias: idp alias name |
|
|
|
|
|
:type idp_alias: str |
|
|
|
|
|
:returns: Keycloak server response |
|
|
|
|
|
:rtype: dict |
|
|
""" |
|
|
""" |
|
|
params_path = {"realm-name": self.realm_name, "alias": idp_alias} |
|
|
params_path = {"realm-name": self.realm_name, "alias": idp_alias} |
|
|
data_raw = self.raw_delete(urls_patterns.URL_ADMIN_IDP.format(**params_path)) |
|
|
data_raw = self.raw_delete(urls_patterns.URL_ADMIN_IDP.format(**params_path)) |
|
@ -514,10 +655,13 @@ class KeycloakAdmin: |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_userrepresentation |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_userrepresentation |
|
|
|
|
|
|
|
|
:param payload: UserRepresentation |
|
|
:param payload: UserRepresentation |
|
|
|
|
|
:type payload: dict |
|
|
:param exist_ok: If False, raise KeycloakGetError if username already exists. |
|
|
:param exist_ok: If False, raise KeycloakGetError if username already exists. |
|
|
Otherwise, return existing user ID. |
|
|
Otherwise, return existing user ID. |
|
|
|
|
|
:type exist_ok: bool |
|
|
|
|
|
|
|
|
:return: UserRepresentation |
|
|
:return: UserRepresentation |
|
|
|
|
|
:rtype: dict |
|
|
""" |
|
|
""" |
|
|
params_path = {"realm-name": self.realm_name} |
|
|
params_path = {"realm-name": self.realm_name} |
|
|
|
|
|
|
|
@ -540,8 +684,10 @@ class KeycloakAdmin: |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_users_resource |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_users_resource |
|
|
|
|
|
|
|
|
:param query: (dict) Query parameters for users count |
|
|
:param query: (dict) Query parameters for users count |
|
|
|
|
|
:type query: dict |
|
|
|
|
|
|
|
|
:return: counter |
|
|
:return: counter |
|
|
|
|
|
:rtype: int |
|
|
""" |
|
|
""" |
|
|
query = query or dict() |
|
|
query = query or dict() |
|
|
params_path = {"realm-name": self.realm_name} |
|
|
params_path = {"realm-name": self.realm_name} |
|
@ -557,8 +703,10 @@ class KeycloakAdmin: |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_userrepresentation |
|
|
https://www.keycloak.org/docs-api/18.0/rest-api/index.html#_userrepresentation |
|
|
|
|
|
|
|
|
:param username: id in UserRepresentation |
|
|
:param username: id in UserRepresentation |
|
|
|
|
|
:type username: str |
|
|
|
|
|
|
|
|
:return: user_id |
|
|
:return: user_id |
|
|
|
|
|
:rtype: str |
|
|
""" |
|
|
""" |
|
|
lower_user_name = username.lower() |
|
|
lower_user_name = username.lower() |
|
|
users = self.get_users(query={"search": lower_user_name}) |
|
|
users = self.get_users(query={"search": lower_user_name}) |
|
@ -2870,7 +3018,7 @@ class KeycloakAdmin: |
|
|
def get_required_action_by_alias(self, action_alias): |
|
|
def get_required_action_by_alias(self, action_alias): |
|
|
"""Get a required action by its alias. |
|
|
"""Get a required action by its alias. |
|
|
|
|
|
|
|
|
:param action_alias: the alias of the requried action. |
|
|
|
|
|
|
|
|
:param action_alias: the alias of the required action. |
|
|
:type action_alias: str |
|
|
:type action_alias: str |
|
|
:return: the required action (RequiredActionProviderRepresentation). |
|
|
:return: the required action (RequiredActionProviderRepresentation). |
|
|
:rtype: dict |
|
|
:rtype: dict |
|
|