Clients et applications 15 min de lecture

Tester l'authentification avec un client

Direct Access Grant (Resource Owner Password)

Ce flux permet d'obtenir un token directement avec un login/mot de passe. Utile pour les tests, mais a eviter en production.

# Obtenir un token pour un utilisateur
curl -s -X POST "http://localhost:8080/realms/mon-application/protocol/openid-connect/token" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=password" \
  -d "client_id=mon-frontend" \
  -d "username=jean.dupont" \
  -d "password=motdepasse123" | jq .

# Avec un client confidentiel
curl -s -X POST "http://localhost:8080/realms/mon-application/protocol/openid-connect/token" \
  -d "grant_type=password" \
  -d "client_id=mon-backend" \
  -d "client_secret=mon-secret-securise" \
  -d "username=jean.dupont" \
  -d "password=motdepasse123" | jq .

Client Credentials Grant

Ce flux permet a un client confidentiel d'obtenir un token sans utilisateur (service-to-service).

# Token machine-to-machine (pas d'utilisateur)
curl -s -X POST "http://localhost:8080/realms/mon-application/protocol/openid-connect/token" \
  -d "grant_type=client_credentials" \
  -d "client_id=mon-backend" \
  -d "client_secret=mon-secret-securise" | jq .

Introspection de token

# Verifier un token
curl -s -X POST "http://localhost:8080/realms/mon-application/protocol/openid-connect/token/introspect" \
  -d "client_id=mon-backend" \
  -d "client_secret=mon-secret-securise" \
  -d "token=$ACCESS_TOKEN" | jq .

UserInfo endpoint

# Obtenir les informations de l'utilisateur connecte
curl -s -H "Authorization: Bearer $ACCESS_TOKEN" \
  "http://localhost:8080/realms/mon-application/protocol/openid-connect/userinfo" | jq .