diff --git a/src/keycloak/keycloak_admin.py b/src/keycloak/keycloak_admin.py index e740ce1..8ee275a 100644 --- a/src/keycloak/keycloak_admin.py +++ b/src/keycloak/keycloak_admin.py @@ -88,7 +88,7 @@ class KeycloakAdmin: def __init__( self, - server_url, + server_url=None, username=None, password=None, token=None, diff --git a/tests/test_keycloak_admin.py b/tests/test_keycloak_admin.py index e984023..454acfc 100644 --- a/tests/test_keycloak_admin.py +++ b/tests/test_keycloak_admin.py @@ -9,7 +9,7 @@ import pytest from dateutil import parser as datetime_parser import keycloak -from keycloak import KeycloakAdmin, KeycloakOpenID +from keycloak import KeycloakAdmin, KeycloakOpenID, KeycloakOpenIDConnection from keycloak.connection import ConnectionManager from keycloak.exceptions import ( KeycloakAuthenticationError, @@ -111,6 +111,17 @@ def test_keycloak_admin_init(env): is None ) + keycloak_connection = KeycloakOpenIDConnection( + server_url=f"http://{env.KEYCLOAK_HOST}:{env.KEYCLOAK_PORT}", + username=env.KEYCLOAK_ADMIN, + password=env.KEYCLOAK_ADMIN_PASSWORD, + realm_name="master", + client_id="admin-cli", + verify=True, + ) + keycloak_admin = KeycloakAdmin(connection=keycloak_connection) + assert keycloak_admin.token + def test_realms(admin: KeycloakAdmin): """Test realms.