From bd06ace4c2374bea08fcda02719732e3125aab62 Mon Sep 17 00:00:00 2001 From: "Shon T. Urbas" Date: Wed, 6 Dec 2017 11:06:49 -0500 Subject: [PATCH] revert to payload --- keycloak/keycloak_admin.py | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/keycloak/keycloak_admin.py b/keycloak/keycloak_admin.py index c24dbc3..67fefcf 100644 --- a/keycloak/keycloak_admin.py +++ b/keycloak/keycloak_admin.py @@ -106,7 +106,7 @@ class KeycloakAdmin: data_raw = self.connection.raw_get(URL_ADMIN_USERS.format(**params_path), **query) return raise_error_from_response(data_raw, KeycloakGetError) - def create_user(self, username, email='', firstName='', lastName='', emailVerified=False, enabled=True): + def create_user(self, payload): """ Create a new user Username must be unique @@ -115,17 +115,11 @@ class KeycloakAdmin: :param payload: UserRepresentation + :return: UserRepresentation """ - data={} - data["username"]=username - data["email"]=email - data["firstName"]=firstName - data["lastName"]=lastName - data["emailVerified"]=emailVerified - data["enabled"]=enabled params_path = {"realm-name": self.realm_name} data_raw = self.connection.raw_post(URL_ADMIN_USERS.format(**params_path), - data=json.dumps(data)) + data=json.dumps(payload)) return raise_error_from_response(data_raw, KeycloakGetError, expected_code=201) def users_count(self): @@ -138,7 +132,6 @@ class KeycloakAdmin: data_raw = self.connection.raw_get(URL_ADMIN_USERS_COUNT.format(**params_path)) return raise_error_from_response(data_raw, KeycloakGetError) - def get_user_id(self, username): """ Get internal keycloak user id from username @@ -184,14 +177,9 @@ class KeycloakAdmin: :return: Http response """ - data={} - data["username"]=username - data["email"]=email - data["firstName"]=firstName - data["lastName"]=lastName - data["emailVerified"]=emailVerified - data["enabled"]=enabled - params_path = {"realm-name": self.realm_name} + data = {"username": username, "email": email, "firstName": firstName, "lastName": lastName, + "emailVerified": emailVerified, "enabled": enabled} + params_path = {"realm-name": self.realm_name, "id": user_id} data_raw = self.connection.raw_put(URL_ADMIN_USER.format(**params_path), data=json.dumps(data))