python-keycloak
python-keycloak copied to clipboard
authentication flow creation Failed
Hi, I got this error when I tried to create an authentication flow:
successfully authenticate with keycloak
from keycloak import KeycloakAdmin keycloak_admin = KeycloakAdmin(server_url="http://10.3.7.220/abc/auth/", username='admin', password='admin', realm_name="abc", user_realm_name="abc")
I can get a list of dict representing the authentication flows
flows = keycloak_admin.get_authentication_flows()
Get this error when I tried to create or copy an authentication flow
payload = {'alias': 'Guac-Browser with group enforcement test'}
keycloak_admin.create_authentication_flow(payload, skip_exists=False)
Traceback (most recent call last):
File "
File "/home/lzhao/.local/lib/python3.6/site-packages/keycloak/keycloak_admin.py", line 1363, in create_authentication_flow
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists)
File "/home/lzhao/.local/lib/python3.6/site-packages/keycloak/exceptions.py", line 108, in raise_error_from_response
response_body=response.content)
keycloak.exceptions.KeycloakGetError: 400: b'{"error":"unknown_error"}'
thanks in advance
The payload must be in json.
@jsalatiel
Thank you for the reply, I tried to convert payload to json and it's still not working
import json a = {'alias': 'Guac-Browser with group enforcement test'} payload = json.dumps(a) type(payload) <class 'str'>
keycloak_admin.create_authentication_flow(payload, skip_exists=False) Traceback (most recent call last): File "
", line 1, in File "/home/lzhao/.local/lib/python3.6/site-packages/keycloak/keycloak_admin.py", line 1363, in create_authentication_flow return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists) File "/home/lzhao/.local/lib/python3.6/site-packages/keycloak/exceptions.py", line 108, in raise_error_from_response response_body=response.content) keycloak.exceptions.KeycloakGetError: 500: b'{"error":"unknown_error"}' payload = json.dump(a) Traceback (most recent call last): File " ", line 1, in TypeError: dump() missing 1 required positional argument: 'fp'
BTW, in the "create_authentication_flow" function, there is a json.dumps(payload), so I guess payload should be dict
def create_authentication_flow(self, payload, skip_exists=False):
"""
Create a new authentication flow
AuthenticationFlowRepresentation
https://www.keycloak.org/docs-api/8.0/rest-api/index.html#_authenticationflowrepresentation
:param payload: AuthenticationFlowRepresentation
:param skip_exists: If true then do not raise an error if authentication flow already exists
:return: Keycloak server response (RoleRepresentation)
"""
params_path = {"realm-name": self.realm_name}
data_raw = self.raw_post(URL_ADMIN_FLOWS.format(**params_path),
data=json.dumps(payload))
return raise_error_from_response(data_raw, KeycloakGetError, expected_codes=[201], skip_exists=skip_exists)
hi @jsalatiel
could you help to check this one?
I will check tomorrow and let you know
My minimal payload is
payload = {"alias":"xxx", "providerId":"basic-flow", "topLevel":True, "builtIn":False}
Might work without topLevel
or bultIn
but probably causes keycloak issues ... (providerID = basic-flow / client-flow)
I use these as my payloads: flow_payload = { "alias": root_alias , "builtIn": False , "description": "", "providerId": "basic-flow", "topLevel": True } authn_payload = {"alias":authn_alias ,"description":"","provider":"registration-page-form","type":"basic-flow"} authz_payload = {"alias":authz_alias ,"description":"","provider":"registration-page-form","type":"basic-flow"}
I may have run into this issue as well, and it seems fixed in 0.26.1.
This call, the payload was not properly JSON-encoded: https://github.com/marcospereirampj/python-keycloak/blob/0.24.0/keycloak/keycloak_admin.py#L1376
This one is: https://github.com/marcospereirampj/python-keycloak/blob/0.26.1/keycloak/keycloak_admin.py#L1427