OAuth2 — Flux Authorization Code
MOCOSAG utilise OAuth2 pour l'authentification. Le flux principal est le Client Credentials pour les intégrations serveur-à-serveur.
Client Credentials (machine-to-machine)
curl -X POST https://sandbox.api.mocosag.com/oauth/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "grant_type=client_credentials" \
-d "client_id=$CLIENT_ID" \
-d "client_secret=$CLIENT_SECRET" \
-d "scope=onboarding:read onboarding:write"
Authorization Code (utilisateur)
Pour les applications qui agissent au nom d'un utilisateur :
- Redirigez vers
/oauth/authorize?response_type=code&client_id=...&scope=...&redirect_uri=... - L'utilisateur s'authentifie et autorise
- Échangez le
codecontre un token viaPOST /oauth/token
Refresh Token
curl -X POST https://sandbox.api.mocosag.com/oauth/token \
-d "grant_type=refresh_token" \
-d "refresh_token=$REFRESH_TOKEN" \
-d "client_id=$CLIENT_ID"
Bonnes pratiques
- Stockez les tokens de manière sécurisée (jamais côté client)
- Renouvelez les tokens avant expiration (
expires_in- 60s marge) - Utilisez le scope minimal nécessaire