Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Delegation, impersonation, and actor tokens

An exchanged token is about one party and presented by another, and the request has to label each token it carries. This lesson labels the photo API's subject token, compares a token that makes its holder indistinguishable from Ava with one that names who acts, and follows the printer's support console as it brings in an agent with may_act and an actor token.

The subject token

In The problem token exchange solves, the photo API asked the authorization server for a token to use at the storage service. The new token will be about Ava, user-2048, but she will not be the one presenting it. The photo API will. Whether the storage service is told that changes what it can check, what its records show afterwards and how much harm a misused token can do.

An exchange request can carry two tokens to help the authorization server decide. One says whom the new token will be about; the other, when present, says who will act. Two parameters appear in every exchange. subject_token carries a token representing the party on whose behalf the request is made, and that party is usually the subject of the token issued in response. subject_token_type says what kind of token it is, because a server that accepts several kinds needs to know how to read and validate the one in front of it.

All domains, identifiers, and tokens in these examples are fictional. For the photo API, the subject token is the printer's access token, exactly as it arrived in the Authorization header. Shortened, and with the type shown before form encoding:

subject_token=eyJhbGciOiJFUzI1NiIsImtpZCI6InBob3Rvcy0yMDI2LTA5IiwidHlwIjoiYXQrand0In0.eyJpc3Mi...
subject_token_type=urn:ietf:params:oauth:token-type:access_token

The photo API labels it an access token because that is what it is: an access token issued by this authorization server. The label would be the same if the token were an opaque string. The photo API happens to validate it as a JWT when it serves the printer's request, but the exchange does not depend on that.

Token type identifiers

Token types are named with URIs. Token exchange defines five and uses a sixth from the JWT specification:

Token type identifiers
IdentifierThe token is
urn:ietf:params:oauth:token-type:access_tokenAn OAuth access token issued by this authorization server.
urn:ietf:params:oauth:token-type:refresh_tokenAn OAuth refresh token issued by this authorization server.
urn:ietf:params:oauth:token-type:id_tokenAn OpenID Connect ID token.
urn:ietf:params:oauth:token-type:jwtA JWT, whatever its purpose.
urn:ietf:params:oauth:token-type:saml2A SAML 2.0 assertion, base64url-encoded.
urn:ietf:params:oauth:token-type:saml1A SAML 1.1 assertion, base64url-encoded.

The list mixes two kinds of description. For tokens this authorization server issued, the identifier says what the token was issued for: an access token or a refresh token. For tokens from elsewhere, it says the format, so the server knows how to parse what it receives. The same bytes can therefore be described in two ways. access_token means "an access token you issued, whatever its format." jwt means "a JWT, whatever it is for", the label a client would use for an assertion from another issuer, like the one Lantern's identity provider signed in JWT and SAML assertion grants. Other URIs can name other types.

A client can also ask for a particular type in return with requested_token_type, using the same identifiers. It is optional. Without it, the server chooses, often from what the target service needs.

Two answers to who is acting

With the subject settled, the new token still has to say, or not say, who is presenting it. Token exchange recognizes two answers.

With impersonation, the new token is simply about Ava. The storage service sees a subject of user-2048, and the token makes no statement that anyone else is acting for her. Within the rights the token carries, whoever presents it is treated as Ava and cannot be told apart from her. Other parts of the system, such as the authorization server's own records, may know that an exchange took place, but the token does not tell its recipient.

With delegation, the token is still about Ava, and it also identifies the party acting for her. The photo API keeps its own identity. The storage service can see that the photo API is reading Ava's files on her behalf, and can treat that differently from Ava reading them herself, or from some other service trying the same thing.

Which form a new token takes is the authorization server's decision, made by its policy for the requesting client and the target. A client can supply information about the actor, but the server decides what the token says.

Recording the actor

Delegation is recorded in a JWT with the act (actor) claim. Its value is a JSON object whose members identify the party that is acting.

The photo service's policy is to issue delegation tokens for the photo API's calls, naming the photo API as the actor, so the storage token includes these claims, among others:

{
  "sub": "user-2048",
  "client_id": "photo-api",
  "act": {
    "sub": "photo-api"
  }
}

sub is still Ava. Inside act, sub names the photo API, using its client ID because that is how the photo service knows it. client_id names the client that requested this token. Here the client and the actor are the same party, so both say photo-api, but they answer different questions: which registered client asked for the token, and who is acting for its subject. They differ when the actor is someone other than the client.

Claims inside act only identify the actor. They have no say in whether the token is valid: an exp or aud placed inside act would mean nothing, and the token's top-level claims alone decide where and until when it can be used. When a subject identifier is unique only within its issuer, act can carry iss beside sub.

The photo API's request carried nothing but Ava's token to make this happen, and that rests on a policy choice rather than a protocol rule. The specification's own examples express delegation by sending a second token for the actor, and describe a request with only a subject token as impersonation. Its rules leave the decision to the server, though, and client authentication lets the server decide which clients may receive delegations. The photo API is both the client and the actor, and its client authentication already proves who it is, so the photo service records the authenticated client as the actor. Another server could require the photo API to send a token of its own for the actor role. An actor who is not the client making the request can be identified only that way, as the support console below shows.

An act claim can also contain another act. When a service that received a delegation token exchanges it again, the authorization server can record the earlier actor inside the new one. The outermost act names the current actor, and the nested ones form a history of earlier steps. Following a token exchange follows a chain like that.

The support console

Impersonation is most tempting where people help other people. The printing company's support team uses an internal support console, and when Ava writes in because the cover of her photo book looks wrong, an agent wants to see her order the way she sees it.

The printer runs its own authorization server, https://auth.printer.example, for its internal APIs, including an orders API at https://orders.printer.example. Ava's printer account is customer-8812, and the agent who picks up her request is staff-17. The console is a registered client, support-console.

Two things are missing. The console has no token of Ava's: she never signed in to it, so the token it exchanges has to come from her, at the moment she agrees to the help. And several agents share the console, so its client authentication cannot say which of them is asking. An exchange can bring in both.

Saying who may act

When Ava starts a support chat on the printer website and chooses Let the agent view my order, the website asks the printer's authorization server for a short-lived token that represents her and names the agent. Decoded, its claims read:

{
  "iss": "https://auth.printer.example",
  "sub": "customer-8812",
  "aud": "https://auth.printer.example",
  "scope": "orders.read",
  "iat": 1790845200,
  "exp": 1790847000,
  "jti": "demo-support-grant-5",
  "may_act": {
    "sub": "staff-17"
  }
}

The may_act claim states that a party is authorized to become the actor and act for the token's subject. Like act, its members only identify that party. Here it says that staff-17 may act for customer-8812 within orders.read, for the half hour from 09:00 to 09:30 UTC. The token's audience is the authorization server itself, because nothing else needs to read it, and it reaches the console attached to Ava's support request.

When the token arrives as a subject token, the authorization server compares may_act with the party asking to act. The claim is a statement in a token, not an instruction the server must obey. The server still applies its own policy, such as whether staff-17 holds a support role right now.

The actor token

The actor has two parameters of its own. actor_token carries a token representing the acting party, typically the one that will use the new token, and actor_token_type labels it. The type is required whenever an actor token is present and must not be sent when there is none.

For the agent, the console sends the ID token it received when staff-17 signed in, the signed statement about a sign-in that OpenID Connect defines:

POST /token HTTP/1.1
Host: auth.printer.example
Authorization: Basic c3VwcG9ydC1jb25zb2xlOmRlbW8tb25seS1ub3QtYS1yZWFsLXNlY3JldA==
Content-Type: application/x-www-form-urlencoded

grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange
&subject_token=eyJhbGciOiJFUzI1NiIs...
&subject_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Ajwt
&actor_token=eyJhbGciOiJFUzI1NiIs...
&actor_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Aid_token
&resource=https%3A%2F%2Forders.printer.example
&scope=orders.read

Both tokens are shortened here for display, and the Basic header represents support-console:demo-only-not-a-real-secret. The subject token is labeled jwt because it is neither an access token nor a refresh token, just a JWT written for the authorization server.

One request now identifies three parties. The client authentication speaks for the console, the actor token for the agent, and the subject token for Ava. The server checks that the actor token's subject is the party named in may_act, and returns a delegation token whose claims read:

{
  "iss": "https://auth.printer.example",
  "sub": "customer-8812",
  "aud": "https://orders.printer.example",
  "client_id": "support-console",
  "scope": "orders.read",
  "iat": 1790845500,
  "exp": 1790846100,
  "jti": "demo-support-token-2",
  "act": {
    "sub": "staff-17"
  }
}

Here the client and the actor differ: client_id names the console, and act names the agent. The token lasts ten minutes, from 09:05 to 09:15 UTC, and says plainly that staff-17 is acting for customer-8812. The orders API can let the agent view the order while refusing to change the delivery address, record the agent's actions under both names, and show Ava afterwards that support looked at her order.

Keeping impersonation narrow

Suppose the printer's authorization server issued the console an impersonation token instead. It would be identical except for one missing claim:

{
  "iss": "https://auth.printer.example",
  "sub": "customer-8812",
  "aud": "https://orders.printer.example",
  "client_id": "support-console",
  "scope": "orders.read",
  "iat": 1790845500,
  "exp": 1790846100,
  "jti": "demo-support-token-1"
}

To the orders API, this token is Ava. Anything the agent does with it is recorded as hers. Its client_id reveals that the support console asked for it, but not who was sitting at the console.

demo-support-token-2

sub
customer-8812
client_id
support-console
scope
orders.read
act
sub: staff-17

Orders API records staff-17 for Ava

demo-support-token-1

sub
customer-8812
client_id
support-console
scope
orders.read
act
None

Orders API records Ava

A compromised console, or an agent acting in bad faith, leaves no trace there of who really acted.

The two support console tokens differ by one claim. With act, the orders API can tell the agent from Ava; without it, every record says Ava acted.

The property that defines impersonation is also its danger. A party that impersonates Ava receives her rights within the token's context and cannot be told apart from her there. An agent holding an impersonation token for her account can do whatever the token allows her to do, and every record at the API says she did it. A compromised console, or an agent acting in bad faith, leaves no trace there of who really acted.

Sometimes impersonation is still the practical choice. An older API might understand only tokens about the customer, or a problem might appear only when a request looks exactly like the customer's own. When an authorization server issues impersonation tokens, it keeps them small:

  • A narrow scope, such as viewing orders, and never payment details or account security settings.
  • A short lifetime. The specification notes that impersonation can be limited in scope, in time, or even to a single use.
  • Only specific clients, such as the support console, may request one, and only for agents whose current role allows it.
  • A reason attached, such as an open support request, and a record at the authorization server naming both the agent and the customer, because the token itself will not.
  • A notice to the customer that support accessed the account.

Delegation is the better default wherever the recipient can understand it. It costs one claim, and it keeps the actor visible to the API making the decision and to anyone reading that API's records later.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

Why does the support console send an actor token when the photo API does not? 1 of 3

Choose one answer.

Why should an impersonation token for the support console be narrow and short-lived? 2 of 3

Choose one answer.

Ava's subject token says may_act staff-17, but staff-30 has taken over her chat, and the console sends staff-30's ID token as the actor token. What should the printer's authorization server do? 3 of 3

Choose one answer.

Try it in the Lab

Try a Capture the Flag challenge

Apply this lesson against an isolated, intentionally vulnerable application. Capture a flag, explain the mistake, then repair and retest it.

  1. The Unauthorized Delegation Difficulty 4 of 5 · About 50 minutes · API target

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity