From bf30c0a4091bfe777eb824a918ef0f935ee4c024 Mon Sep 17 00:00:00 2001 From: Guillaume Troupel Date: Wed, 27 Nov 2019 17:36:44 +0100 Subject: [PATCH] adds user_realm_name to KeycloakAdmin fixes #41 Adds a optional new parameter _user_realm_name_ that takes _realm_name_ value if not defined. The admin token is retrieved from the given _user_realm_name_ but all methods are run under _realm_name_. This allows to have an admin user in another realm (ie: master). --- keycloak/keycloak_admin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/keycloak/keycloak_admin.py b/keycloak/keycloak_admin.py index 5d57661..423687e 100644 --- a/keycloak/keycloak_admin.py +++ b/keycloak/keycloak_admin.py @@ -45,7 +45,7 @@ class KeycloakAdmin: PAGE_SIZE = 100 - def __init__(self, server_url, username, password, realm_name='master', client_id='admin-cli', verify=True, client_secret_key=None): + def __init__(self, server_url, username, password, realm_name='master', client_id='admin-cli', verify=True, client_secret_key=None, user_realm_name=None): """ :param server_url: Keycloak server url @@ -62,7 +62,7 @@ class KeycloakAdmin: self._realm_name = realm_name # Get token Admin - keycloak_openid = KeycloakOpenID(server_url=server_url, client_id=client_id, realm_name=realm_name, + keycloak_openid = KeycloakOpenID(server_url=server_url, client_id=client_id, realm_name=user_realm_name or realm_name, verify=verify, client_secret_key=client_secret_key) grant_type = ["password"]