Échange de jetons (RFC 8693)
Découvrez l’extension OAuth2 d’échange de jetons, qui permet aux services d’échanger un jeton contre un autre pour prendre en charge la délégation et l’usurpation d’identité entre services.
Échange de jetons (RFC 8693) est une leçon OAuth2 & OpenID Connect Deep Dive gratuite sur CoddyKit. Ceci est la leçon 4 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage OAuth2 & OpenID Connect Deep Dive, et ta progression se synchronise sur le web et l'application CoddyKit. Le cours OAuth2 & OpenID Connect Deep Dive comprend 4 leçons au total.
Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.
What Problem Does It Solve?
In a microservices world, Service A receives a token from a user, then must call Service B on the user's behalf. Forwarding the original token everywhere is risky — it may have the wrong audience or too-broad scopes.
Token Exchange (RFC 8693) lets a service trade an incoming token for a new, narrower or differently-scoped token from the authorization server.
Delegation vs Impersonation
Two distinct patterns:
- Impersonation — the new token looks like it belongs purely to the user; downstream cannot tell a middle service was involved.
- Delegation — the new token records both the user and the acting service via an
actclaim, preserving the chain.
The Grant Type
Token Exchange defines a new grant type sent to the standard token endpoint:
urn:ietf:params:oauth:grant-type:token-exchange
It does not need a browser or user interaction — it is a direct back-channel call.
Key Parameters
The request uses several parameters:
subject_token+subject_token_type— the token to exchange.actor_token— optional, identifies the acting party.audience/resource— the target service.scope— requested scopes for the new token.
Token Type URIs
Token types are identified by URIs, for example:
urn:ietf:params:oauth:token-type:access_tokenurn:ietf:params:oauth:token-type:jwturn:ietf:params:oauth:token-type:id_token
An Exchange Request
Service A exchanges the user's access token for a token scoped to Service B:
POST /token HTTP/1.1
Host: auth.example.com
Content-Type: application/x-www-form-urlencoded
grant_type=urn:ietf:params:oauth:grant-type:token-exchange
&subject_token=eyJhbGciOi...
&subject_token_type=urn:ietf:params:oauth:token-type:access_token
&audience=https://serviceB.example.com
&scope=read:ordersThe Exchange Response
The response includes the new token plus an issued_token_type telling the caller what it received.
{
"access_token": "eyJ0eXAiOi...",
"issued_token_type": "urn:ietf:params:oauth:token-type:access_token",
"token_type": "Bearer",
"expires_in": 600,
"scope": "read:orders"
}The act Claim
In delegation mode, the issued JWT contains an act (actor) claim nesting the acting party inside the subject. This lets the resource server audit who acted on whose behalf.
{
"sub": "user-42",
"aud": "https://serviceB.example.com",
"act": { "sub": "service-A" }
}Downscoping
A powerful use is downscoping: a service holding a broad token exchanges it for one with fewer scopes before passing it downstream. This honors least privilege so a compromised downstream service cannot do more than it needs.
When to Use It
Reach for Token Exchange when:
- Crossing trust or audience boundaries between services.
- You need an auditable delegation chain.
- You want to narrow scopes for downstream calls.
Avoid blindly forwarding the original token across services.
Security Notes
The authorization server must authenticate the requesting client and verify it is permitted to exchange the subject token for the requested audience. Always set a correct aud so tokens cannot be replayed against other services.
Quick Check
Check your grasp of Token Exchange.
Recap
Token Exchange (RFC 8693) trades one token for another via grant type token-exchange.
- Supports impersonation and delegation (the
actclaim). - Lets services downscope and re-audience tokens for downstream calls.
- Requires the AS to authenticate the client and validate the target audience.
Questions Fréquemment Posées
La leçon « Échange de jetons (RFC 8693) » est-elle gratuite ?
Oui — le texte complet de « Échange de jetons (RFC 8693) » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours OAuth2 & OpenID Connect Deep Dive, passe à CoddyKit PRO. Le cours OAuth2 & OpenID Connect Deep Dive comprend 4 leçons au total.
Qu'est-ce que j'apprendrai dans « Échange de jetons (RFC 8693) » ?
Découvrez l’extension OAuth2 d’échange de jetons, qui permet aux services d’échanger un jeton contre un autre pour prendre en charge la délégation et l’usurpation d’identité entre services. Tu pratiques OAuth2 & OpenID Connect Deep Dive avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.
Dois-je avoir de l'expérience pour commencer OAuth2 & OpenID Connect Deep Dive ?
Aucune expérience préalable n'est requise. OAuth2 & OpenID Connect Deep Dive sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 4 sur 4.
Combien de temps prend la leçon « Échange de jetons (RFC 8693) » ?
La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.
Peux-tu écrire et exécuter du code dans cette leçon OAuth2 & OpenID Connect Deep Dive ?
Oui. Chaque leçon OAuth2 & OpenID Connect Deep Dive inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.
Toutes les leçons de ce cours
- PKCE pour les clients publics
- Jetons d’actualisation et portées
- Identifiants du propriétaire de la ressource
- Échange de jetons (RFC 8693)