← Retour Docs

Identité visiteur vérifiée

Reliez de façon fiable vos utilisateurs SaaS connectés aux conversations SetChat (chats, tickets, flows) via un token signé côté backend.

Architecture recommandée

  1. Votre backend valide l'utilisateur connecté.
  2. Votre backend obtient un visitor token signé (S2S).
  3. Votre frontend passe le token au widget SetChat.
  4. Au logout/changement de compte, le widget est réinitialisé.

Payload conseillé

{
  "siteApiKey": "site_xxx",
  "externalUserId": "usr_123",
  "email": "user@client.com",
  "name": "Jane Doe",
  "provider": "setacademy",
  "metadata": { "role": "admin", "plan": "business" }
}

Contrat API SetChat (S2S)

Point de terminaison : POST /api/widget/visitor-token

Authentification : Authorization: Bearer <SETCHAT_SERVER_TOKEN>

Corps : siteApiKey, externalUserId, email, name, provider, metadata

Réponse : { token, expiresIn, expires_in }

Test rapide (copy/paste cURL)

En 30 secondes, testez le mint S2S depuis votre terminal avec vos variables.

SETCHAT_API_URL=https://api.setchat.co
SETCHAT_SERVER_TOKEN=replace_with_server_token
SETCHAT_SITE_API_KEY=site_xxx

curl -X POST "$SETCHAT_API_URL/api/widget/visitor-token" \
  -H "Authorization: Bearer $SETCHAT_SERVER_TOKEN" \
  -H "Content-Type: application/json" \
  -d "{
    \"siteApiKey\": \"$SETCHAT_SITE_API_KEY\",
    \"externalUserId\": \"usr_demo_123\",
    \"email\": \"demo@example.com\",
    \"name\": \"Demo User\",
    \"provider\": \"setacademy\",
    \"metadata\": {\"role\": \"admin\"}
  }"

Réponse attendue (exemple) :

{
  "token": "eyJhbGciOi...",
  "expiresIn": 300,
  "expires_in": 300,
  "expiresInLabel": "5m"
}

Si vous obtenez 401 ou 400, consultez la page de dépannage (identité vérifiée).

Rotation et révocation (ops)

  • Rotation du jeton S2S : POST /api/tenants/:id/widget-identity/s2s-token/rotate
  • Révocation des anciens jetons : POST /api/tenants/:id/widget-identity/s2s-token/revoke-previous
  • Schéma recommandé : rotation — déploiement côté client — révocation des jetons précédents.
  • Le jeton n'est affiché qu'une seule fois lors de la rotation.

Sécurité

  • Ne jamais signer le token côté navigateur.
  • Secret de signature stocké uniquement côté serveur.
  • Durée de vie courte recommandée : 5 à 15 minutes.