2.7 KiB
Keycloak – lire les rôles et la config UnionFlow (curl)
Base URL Keycloak : http://localhost:8180
Identifiants admin : username=admin, password=admin.
1. Obtenir un token admin (realm master)
curl -s -X POST "http://localhost:8180/realms/master/protocol/openid-connect/token" ^
-H "Content-Type: application/x-www-form-urlencoded" ^
-d "username=admin" ^
-d "password=admin" ^
-d "grant_type=password" ^
-d "client_id=admin-cli"
Sous Linux/macOS, remplacer ^ par \.
Réponse attendue : JSON avec access_token, expires_in, etc.
Copier la valeur de access_token pour les appels suivants (ou parser avec jq : ... | jq -r .access_token).
2. Lister les rôles du realm unionflow
Remplacez ACCESS_TOKEN par le token obtenu à l’étape 1.
curl -s -H "Authorization: Bearer ACCESS_TOKEN" ^
"http://localhost:8180/admin/realms/unionflow/roles"
Rôles typiques côté UnionFlow : ADMIN, ADMIN_ORGANISATION, MEMBRE, MODERATEUR, etc.
3. Récupérer la configuration du realm unionflow
curl -s -H "Authorization: Bearer ACCESS_TOKEN" ^
"http://localhost:8180/admin/realms/unionflow"
Contient la config générale du realm (nom, login, thème, tokens, etc.).
4. Rôles par client (ex. application UnionFlow)
Si les rôles sont définis sur un client (client scope), lister les rôles du client :
# Récupérer l’id du client (ex. unionflow-mobile ou account)
curl -s -H "Authorization: Bearer ACCESS_TOKEN" ^
"http://localhost:8180/admin/realms/unionflow/clients?clientId=unionflow-mobile"
# Puis lister les rôles du client (remplacer CLIENT_UUID par l’id du client)
curl -s -H "Authorization: Bearer ACCESS_TOKEN" ^
"http://localhost:8180/admin/realms/unionflow/clients/CLIENT_UUID/roles"
5. Exemple PowerShell (token + rôles en une fois)
$body = @{
username = 'admin'
password = 'admin'
grant_type = 'password'
client_id = 'admin-cli'
}
$tokenResponse = Invoke-RestMethod -Uri 'http://localhost:8180/realms/master/protocol/openid-connect/token' -Method Post -Body $body -ContentType 'application/x-www-form-urlencoded'
$token = $tokenResponse.access_token
# Rôles du realm unionflow
Invoke-RestMethod -Uri 'http://localhost:8180/admin/realms/unionflow/roles' -Headers @{ Authorization = "Bearer $token" }
# Config du realm unionflow
Invoke-RestMethod -Uri 'http://localhost:8180/admin/realms/unionflow' -Headers @{ Authorization = "Bearer $token" }
Note
L’API Admin Keycloak (/admin/realms/...) exige un utilisateur du realm master (admin). Les rôles visibles dans le JWT des utilisateurs connectés à l’app (realm unionflow) viennent du realm unionflow (realm roles ou client roles selon la config).