Grant Types


TOSIAM supporte huit grant types OAuth 2.0. Chaque grant type correspond à un scénario d’utilisation précis.

Authorization Code (+ PKCE)

Le flux standard pour les applications web et mobiles. Le client redirige l’utilisateur vers TOSIAM, reçoit un code d’autorisation, puis l’échange contre un access token.

1. GET /oauth2/{realm}/authorize
   ?response_type=code
   &client_id=mon-client
   &redirect_uri=https://app.example.com/callback
   &scope=openid email
   &code_challenge=...          ← PKCE (recommandé)
   &code_challenge_method=S256

2. POST /oauth2/{realm}/access_token
   grant_type=authorization_code
   &code=AUTH_CODE
   &redirect_uri=https://app.example.com/callback
   &code_verifier=...           ← PKCE

PKCE (RFC 7636) est recommandé pour tous les clients, obligatoire pour les clients publics (SPA, mobile).


Client Credentials

Pour les appels machine-to-machine (M2M) sans utilisateur. Le client s’authentifie directement avec ses propres credentials.

POST /oauth2/{realm}/access_token
Authorization: Basic base64(client_id:client_secret)
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials&scope=api:read

Resource Owner Password (ROPC)

L’utilisateur transmet directement ses credentials au client, qui les envoie à TOSIAM. Déprécié dans OAuth 2.1 — à éviter pour les nouveaux projets.

POST /oauth2/{realm}/access_token
grant_type=password
&username=alice
&password=Secret1234!
&client_id=mon-client
&scope=openid

Refresh Token

Renouveler un access token expiré sans ré-authentification de l’utilisateur.

POST /oauth2/{realm}/access_token
grant_type=refresh_token
&refresh_token=REFRESH_TOKEN
&client_id=mon-client

Device Authorization (RFC 8628)

Pour les appareils sans navigateur (TV, IoT, CLI). L’appareil affiche un code court, l’utilisateur le valide sur un autre appareil.

1. POST /oauth2/{realm}/device/code
   client_id=mon-client&scope=openid

   → Retourne : device_code, user_code, verification_uri, expires_in, interval

2. Afficher à l'utilisateur :
   "Allez sur https://tosiam.example.com/device et entrez : ABCD-1234"

3. L'appareil poll toutes les {interval} secondes :
   POST /oauth2/{realm}/access_token
   grant_type=urn:ietf:params:oauth:grant-type:device_code
   &device_code=DEVICE_CODE
   &client_id=mon-client

CIBA — Client-Initiated Backchannel Authentication (RFC 9126)

Authentification asynchrone “push” : le client demande l’authentification, TOSIAM contacte l’utilisateur (push mobile), l’utilisateur approuve, le client récupère le token.

1. POST /oauth2/{realm}/bc-authorize
   login_hint=alice
   &scope=openid
   &client_notification_token=...
   &binding_message=Connexion depuis l'app MonApp

   → Retourne : auth_req_id, expires_in, interval

2. Poll (ou attendre le callback) :
   POST /oauth2/{realm}/access_token
   grant_type=urn:openid:params:grant-type:ciba
   &auth_req_id=AUTH_REQ_ID
   &client_id=mon-client

Token Exchange (RFC 8693)

Échanger un token existant contre un token d’une autre forme ou pour un autre sujet (délégation, impersonation, cross-service).

POST /oauth2/{realm}/access_token
grant_type=urn:ietf:params:oauth:grant-type:token-exchange
&subject_token=SUBJECT_TOKEN
&subject_token_type=urn:ietf:params:oauth:token-type:access_token
&requested_token_type=urn:ietf:params:oauth:token-type:access_token
&scope=api:read
&audience=https://api.example.com

SAML2 Bearer (RFC 7522)

Échange une assertion SAML2 contre un access token OAuth2. Utile pour les migrations SAML → OAuth2 ou les architectures hybrides.

POST /oauth2/{realm}/access_token
grant_type=urn:ietf:params:oauth:grant-type:saml2-bearer
&assertion=BASE64_SAML_ASSERTION
&scope=openid

Introspection et révocation

# Vérifier un token (RFC 7662)
POST /oauth2/{realm}/introspect
Authorization: Basic base64(client_id:client_secret)
token=ACCESS_TOKEN

# Révoquer un token (RFC 7009)
POST /oauth2/{realm}/token/revoke
token=ACCESS_TOKEN&token_type_hint=access_token
Modifier cette page sur GitHub