From 105218dbee2e9a7fa10c55bd0eae3515e7b1eb10 Mon Sep 17 00:00:00 2001 From: Martin Devlin Date: Mon, 6 Aug 2018 21:51:40 +0100 Subject: [PATCH] Add authentication flow actions --- docs/source/conf.py | 4 +-- keycloak/keycloak_admin.py | 55 ++++++++++++++++++++++++++++++++++++++ keycloak/urls_patterns.py | 4 ++- 3 files changed, 60 insertions(+), 3 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index e8c8591..dd1bfa0 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -60,9 +60,9 @@ author = 'Marcos Pereira' # built documents. # # The short X.Y version. -version = '0.13.1' +version = '0.13.2' # The full version, including alpha/beta/rc tags. -release = '0.13.1' +release = '0.13.2' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/keycloak/keycloak_admin.py b/keycloak/keycloak_admin.py index c9718f5..169d8c5 100644 --- a/keycloak/keycloak_admin.py +++ b/keycloak/keycloak_admin.py @@ -780,6 +780,61 @@ class KeycloakAdmin: data=json.dumps(payload)) return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) + def get_authentication_flows(self): + """ + Get authentication flows. Returns all flow details + + AuthenticationFlowRepresentation + https://www.keycloak.org/docs-api/4.1/rest-api/index.html#_authenticationflowrepresentation + + :return: Keycloak server response (AuthenticationFlowRepresentation) + """ + params_path = {"realm-name": self.realm_name} + data_raw = self.connection.raw_get(URL_ADMIN_FLOWS.format(**params_path)) + return raise_error_from_response(data_raw, KeycloakGetError) + + def create_authentication_flow(self, payload, skip_exists=False): + """ + Create a new authentication flow + + AuthenticationFlowRepresentation + https://www.keycloak.org/docs-api/4.1/rest-api/index.html#_authenticationflowrepresentation + + :param payload: AuthenticationFlowRepresentation + :return: Keycloak server response (RoleRepresentation) + """ + + params_path = {"realm-name": self.realm_name} + data_raw = self.connection.raw_post(URL_ADMIN_FLOWS.format(**params_path), + data=payload) + return raise_error_from_response(data_raw, KeycloakGetError, expected_code=201, skip_exists=skip_exists) + + def get_authentication_flow_executions(self, flow_alias): + """ + Get authentication flow executions. Returns all execution steps + + :return: Response(json) + """ + params_path = {"realm-name": self.realm_name, "flow-alias": flow_alias} + data_raw = self.connection.raw_get(URL_ADMIN_FLOWS_EXECUTIONS.format(**params_path)) + return raise_error_from_response(data_raw, KeycloakGetError) + + def update_authentication_flow_executions(self, payload, flow_alias): + """ + Update an authentication flow execution + + AuthenticationExecutionInfoRepresentation + https://www.keycloak.org/docs-api/4.1/rest-api/index.html#_authenticationexecutioninforepresentation + + :param payload: AuthenticationExecutionInfoRepresentation + :return: Keycloak server response + """ + + params_path = {"realm-name": self.realm_name, "flow-alias": flow_alias} + data_raw = self.connection.raw_put(URL_ADMIN_FLOWS_EXECUTIONS.format(**params_path), + data=payload) + return raise_error_from_response(data_raw, KeycloakGetError, expected_code=204) + def sync_users(self, storage_id, action): """ Function to trigger user sync from provider diff --git a/keycloak/urls_patterns.py b/keycloak/urls_patterns.py index 573a295..4b79bfd 100644 --- a/keycloak/urls_patterns.py +++ b/keycloak/urls_patterns.py @@ -64,5 +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_IDPS = "admin/realms/{realm}/identity-provider/instances" +URL_ADMIN_IDPS = "admin/realms/{realm-name}/identity-provider/instances" +URL_ADMIN_FLOWS = "admin/realms/{realm-name}/authentication/flows" +URL_ADMIN_FLOWS_EXECUTIONS = "admin/realms/{realm-name}/authentication/flows/{flow-alias}/executions"