Browse Source

Merge pull request #150 from MatrixCrawler/master

add function to update a client-scope
pull/155/head
Marcos Pereira 4 years ago
committed by GitHub
parent
commit
7fd8321688
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 32
      keycloak/keycloak_admin.py

32
keycloak/keycloak_admin.py

@ -52,7 +52,7 @@ from .urls_patterns import URL_ADMIN_SERVER_INFO, URL_ADMIN_CLIENT_AUTHZ_RESOURC
class KeycloakAdmin: class KeycloakAdmin:
PAGE_SIZE = 100 PAGE_SIZE = 100
_server_url = None _server_url = None
_username = None _username = None
_password = None _password = None
@ -519,7 +519,7 @@ class KeycloakAdmin:
payload = {"identityProvider": provider_id, "userId": provider_userid, "userName": provider_username} payload = {"identityProvider": provider_id, "userId": provider_userid, "userName": provider_username}
params_path = {"realm-name": self.realm_name, "id": user_id, "provider": provider_id} params_path = {"realm-name": self.realm_name, "id": user_id, "provider": provider_id}
data_raw = self.raw_post(URL_ADMIN_USER_FEDERATED_IDENTITY.format(**params_path), data=json.dumps(payload)) data_raw = self.raw_post(URL_ADMIN_USER_FEDERATED_IDENTITY.format(**params_path), data=json.dumps(payload))
def send_update_account(self, user_id, payload, client_id=None, lifespan=None, redirect_uri=None): def send_update_account(self, user_id, payload, client_id=None, lifespan=None, redirect_uri=None):
""" """
Send an update account email to the user. An email contains a Send an update account email to the user. An email contains a
@ -1330,14 +1330,14 @@ class KeycloakAdmin:
params_path = {"realm-name": self.realm_name} params_path = {"realm-name": self.realm_name}
data_raw = self.raw_get(URL_ADMIN_FLOWS.format(**params_path)) data_raw = self.raw_get(URL_ADMIN_FLOWS.format(**params_path))
return raise_error_from_response(data_raw, KeycloakGetError) return raise_error_from_response(data_raw, KeycloakGetError)
def get_authentication_flow_for_id(self, flow_id): def get_authentication_flow_for_id(self, flow_id):
""" """
Get one authentication flow by it's id/alias. Returns all flow details Get one authentication flow by it's id/alias. Returns all flow details
AuthenticationFlowRepresentation AuthenticationFlowRepresentation
https://www.keycloak.org/docs-api/8.0/rest-api/index.html#_authenticationflowrepresentation https://www.keycloak.org/docs-api/8.0/rest-api/index.html#_authenticationflowrepresentation
:param flow_id: the id of a flow NOT it's alias :param flow_id: the id of a flow NOT it's alias
:return: Keycloak server response (AuthenticationFlowRepresentation) :return: Keycloak server response (AuthenticationFlowRepresentation)
""" """
@ -1403,7 +1403,7 @@ class KeycloakAdmin:
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_codes=[204]) return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
def create_authentication_flow_execution(self, payload, flow_alias): def create_authentication_flow_execution(self, payload, flow_alias):
""" """
Create an authentication flow execution Create an authentication flow execution
@ -1496,6 +1496,22 @@ class KeycloakAdmin:
data=json.dumps(payload)) data=json.dumps(payload))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists) return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists)
def update_client_scope(self, client_scope_id, payload):
"""
Update a client scope
ClientScopeRepresentation: https://www.keycloak.org/docs-api/8.0/rest-api/index.html#_client_scopes_resource
:param client_scope_id: The id of the client scope
:param payload: ClientScopeRepresentation
:return: Keycloak server response (ClientScopeRepresentation)
"""
params_path = {"realm-name": self.realm_name, "scope-id": client_scope_id}
data_raw = self.raw_put(URL_ADMIN_CLIENT_SCOPE.format(**params_path),
data=json.dumps(payload))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[204])
def add_mapper_to_client_scope(self, client_scope_id, payload): def add_mapper_to_client_scope(self, client_scope_id, payload):
""" """
Add a mapper to a client scope Add a mapper to a client scope
@ -1725,18 +1741,18 @@ class KeycloakAdmin:
grant_type = ["password"] grant_type = ["password"]
if self.client_secret_key: if self.client_secret_key:
grant_type = ["client_credentials"] grant_type = ["client_credentials"]
self._token = self.keycloak_openid.token(self.username, self.password, grant_type=grant_type) self._token = self.keycloak_openid.token(self.username, self.password, grant_type=grant_type)
headers = { headers = {
'Authorization': 'Bearer ' + self.token.get('access_token'), 'Authorization': 'Bearer ' + self.token.get('access_token'),
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
if self.custom_headers is not None: if self.custom_headers is not None:
# merge custom headers to main headers # merge custom headers to main headers
headers.update(self.custom_headers) headers.update(self.custom_headers)
self._connection = ConnectionManager(base_url=self.server_url, self._connection = ConnectionManager(base_url=self.server_url,
headers=headers, headers=headers,
timeout=60, timeout=60,

Loading…
Cancel
Save