Keycloak最新版本22.0.3由docker从官方网站下载
我遇到了API和端点问题.所以我想用两个togheter^^
用API我无法登录.所以我做了这个
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)
Login是OK的。在我尝试使用带有API的令牌来检索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()
得到这个错误
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
1条答案
按热度按时间wa7juj8i1#
好的,对不起,这个问题是因为重新启动了docker并重置了配置。真实的错误是这样的
admin-channelhave permission checked客户端身份验证ON标准流直接访问授权
管理员用户已通过电子邮件验证