Keycloak last version 22.0.3 by docker downloaded from official site
I have problems with API and endpoints... So i'm trying to solve using both togheter^^
With API i can't login... So i did this
import requests
from keycloak import KeycloakAdmin
url = "http://0.0.0.0:8080/realms/master/protocol/openid-connect/token"
data = {
'client_id': 'admin-cli',
'grant_type': 'password',
'username': 'admin',
'password': 'admin',
'client_secret': 'YTC8x190ZsrV0pQZAWRqXPw9pKlbzniQ'
}
response = requests.post(url, data=data, verify=False)
if response.status_code == 200:
token_data = response.json()
access_token = token_data['access_token']
print('Access Token:', access_token)
else:
print('Failed to retrieve the access token. Status code:', response.status_code)
And login is ok. After i try to use the token with API to retrieve userinfo
# Configura il client per comunicare con Keycloak
keycloak_admin = KeycloakAdmin(server_url="http://0.0.0.0:8080/",
username="admin",
password="admin",
realm_name="master",
client_id="admin-cli",
verify=False)
# Ottieni la lista degli utenti
users = keycloak_admin.get_users(access_token)
# Stampa la lista degli utenti
for user in users:
print(f"User ID: {user['id']}")
print(f"Username: {user['username']}")
print(f"Email: {user.get('email', 'N/A')}")
print("------")
# Chiudi la sessione
keycloak_admin.logout()
and get this error
Traceback (most recent call last):
File "/home/mirko/flask-app/k2.py", line 32, in <module>
users = keycloak_admin.get_users(access_token)
File "/usr/local/lib/python3.10/dist-packages/keycloak/keycloak_admin.py", line 147, in get_users
data_raw = self.connection.raw_get(URL_ADMIN_USERS.format(**params_path), **query)
TypeError: keycloak.connection.ConnectionManager.raw_get() argument after ** must be a mapping, not str
Ok, sorry, that problem was because a new restart of the docker and reset configuration. The real error is this
admin-cli have permission checked Client Authentication ON Standard Flow Direct Access Grant
And the Admin user is email verified