Contrat API - Impersonation
Objectif
Un admin peut travailler en tant que n’importe quel compte. Un technicien agree peut travailler uniquement en tant que l’un des clients rattaches a son compte revendeur.
Obtenir une session
POST /api/v1/impersonation/sessions
Authentification: compte admin existant ou compte technicien agree.
Corps:
{
"client_id": "manager_123",
"client_email": "client@example.com",
"reason": "Assistance ticket 456"
}
client_id ou client_email est requis. reason est obligatoire, 5 caracteres minimum.
Reponse 201:
{
"success": true,
"token": "jwt",
"expires_at": "2026-10-08T12:30:00.000Z",
"target": {
"manager_id": "manager_123",
"email": "client@example.com",
"display_name": "Client",
"roles": ["client"]
},
"actor": { "role": "technician" }
}
Utiliser le jeton
Envoyer le jeton dans Authorization: Bearer <token> vers la PWA, le portail SSH ou les APIs client.
Le backend resout alors l’identite complete de la cible et ajoute X-Impersonation: <jti> a chaque
reponse auditee.
Le front doit afficher un bandeau visible: Vous travaillez en tant que <nom ou email> - fin dans N min.
Quitter
DELETE /api/v1/impersonation/sessions/:jti
Autorise pour l’auteur de la session ou un admin.
Mes sessions
GET /api/v1/impersonation/sessions/me
Renvoie les sessions actives creees par l’appelant.
Introspection
GET /api/v1/impersonation/introspect
Authentification: Authorization: Bearer <token impersonation>.
Reponse active:
{
"active": true,
"sub": "manager_123",
"act": { "id": "tech_1", "role": "technician" },
"scope": "impersonation",
"expires_at": "2026-10-08T12:30:00.000Z"
}
Reponse inactive:
{ "active": false }
Audit admin
GET /api/v1/admin/impersonation/audit?limit=100&offset=0
Reserve aux admins. Le chemin audite est stocke sans query string.
Erreurs principales
IMPERSONATION_SECRET_MISSING:IMPERSONATION_JWT_SECRETabsent.IMPERSONATION_NESTED_FORBIDDEN: appel depuis une session deja impersonnee.IMPERSONATION_NOT_YOUR_CLIENT: cible non rattachee au technicien.IMPERSONATION_TARGET_FORBIDDEN: un technicien tente une cible admin/partenaire/revendeur.IMPERSONATION_ACTION_FORBIDDEN: action sensible bloquee.TOKEN_INVALIDouTOKEN_EXPIRED: jeton invalide, revoque ou expire.