0Pricing
OAuth2 & OpenID Connect Deep Dive · Урок

Обмен токенами (RFC 8693)

Изучите расширение OAuth2 Token Exchange, позволяющее сервисам обменивать один токен на другой для делегирования полномочий и имитации пользователя между границами сервисов.

«Обмен токенами (RFC 8693)» — бесплатный урок OAuth2 & OpenID Connect Deep Dive на CoddyKit. Это урок 4 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения OAuth2 & OpenID Connect Deep Dive, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс OAuth2 & OpenID Connect Deep Dive содержит 4 уроков всего.

Части этого урока еще не переведены и отображаются на английском.

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 act claim, 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_token
  • urn:ietf:params:oauth:token-type:jwt
  • urn: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:orders

The 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 act claim).
  • Lets services downscope and re-audience tokens for downstream calls.
  • Requires the AS to authenticate the client and validate the target audience.

Часто задаваемые вопросы

Урок «Обмен токенами (RFC 8693)» бесплатный?

Да — полный текст урока «Обмен токенами (RFC 8693)» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс OAuth2 & OpenID Connect Deep Dive, подпишись на CoddyKit PRO. Курс OAuth2 & OpenID Connect Deep Dive содержит 4 уроков всего.

Чему я научусь в уроке «Обмен токенами (RFC 8693)»?

Изучите расширение OAuth2 Token Exchange, позволяющее сервисам обменивать один токен на другой для делегирования полномочий и имитации пользователя между границами сервисов. Ты практикуешь OAuth2 & OpenID Connect Deep Dive с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать OAuth2 & OpenID Connect Deep Dive?

Предыдущий опыт не требуется. OAuth2 & OpenID Connect Deep Dive на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 4 из 4.

Сколько времени занимает урок «Обмен токенами (RFC 8693)»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке OAuth2 & OpenID Connect Deep Dive?

Да. Каждый урок OAuth2 & OpenID Connect Deep Dive включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. PKCE для публичных клиентов
  2. Токены обновления и области доступа
  3. Учётные данные владельца ресурса
  4. Обмен токенами (RFC 8693)
← Назад к OAuth2 & OpenID Connect Deep Dive