From 6c858381cd07f9d17827d0fb71c08fa44f595618 Mon Sep 17 00:00:00 2001 From: Sebastian Marquardt Date: Thu, 23 Aug 2018 11:24:19 +0200 Subject: [PATCH] [11] Fixed function get_user_id to return the correct value --- keycloak/keycloak_admin.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/keycloak/keycloak_admin.py b/keycloak/keycloak_admin.py index 01d558a..fce82ef 100644 --- a/keycloak/keycloak_admin.py +++ b/keycloak/keycloak_admin.py @@ -182,15 +182,8 @@ class KeycloakAdmin: :return: user_id """ - data_raw = self.get_users(query={"username": username}) - data_content = raise_error_from_response(data_raw, KeycloakGetError) - - for user in data_content: - this_use_rname = json.dumps(user["username"]).strip('"') - if this_use_rname == username: - return json.dumps(user["id"]).strip('"') - - return None + users = self.get_users(query={"username": username}) + return next((user["id"] for user in users if user["username"] == username), None) def get_user(self, user_id): """