Skip to content
agentgateway has joined the Agentic AI Foundation — Learn more

For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.

Token exchange

Page as Markdown

Exchange the token that a client sends to the gateway for a token that the backend accepts, by calling an OAuth authorization server.

Exchange the token that a client sends to the gateway for a token that the backend accepts, by calling an OAuth authorization server.

About

Instead of attaching a fixed credential to backend requests, the oauthTokenExchange backend authentication method exchanges the incoming token for a new, backend-specific token at an OAuth authorization server, then forwards that token to the backend. Token exchange is useful when a client authenticates to the gateway with one identity, but the backend requires a different, narrowly scoped token.

The gateway attaches the backend token itself, so the AI models and agents that call through it never see a backend credential. The user’s identity is preserved end-to-end, and the exchange can optionally carry an agent identity acting on behalf of the user (see actorToken), which keeps a consistent identity chain for auditing.

By default, the gateway reads the incoming token from the Authorization: Bearer header, exchanges it at the configured token endpoint, and attaches the returned token to the backend request in the Authorization: Bearer header.

Validation of the incoming token is the job of a route-level policy, such as JWT authentication or MCP authentication, not the exchange itself. The exchange only reads the token and presents it to the authorization server.

Authorization servers that implement these grants include Keycloak, Microsoft Entra ID, Okta, Auth0, and ZITADEL.

Choose an exchange

Two backend authentication methods perform an exchange. Which one you need depends on how many authorization servers are involved.

MethodAuthorization serversUse it when
oauthTokenExchangeOneOne server can issue the backend token from the incoming token.
crossAppAccessTwo, across a trust boundaryThe identity provider that authenticated the user and the authorization server that guards the resource are different parties.

The oauthTokenExchange method supports two grants, and you choose between them with the grantType field.

GrantgrantTypeStandardThe incoming token is sent as
Token exchange (default)tokenExchangeRFC 8693subject_token
JWT bearerjwtBearerRFC 7523assertion

Some identity providers have vendor-specific variants of a grant. Microsoft Entra’s on-behalf-of flow is a variant of the JWT bearer grant, and the JWT bearer guide covers it.

Configuration

The token endpoint is configured as a backend reference: a `host` in `host:port` form and, optionally, connection `policies` such as `backendTLS`. A `host` port of `443` automatically enables backend TLS.

The following table describes the most common oauthTokenExchange fields. For the full set of fields, see oauthTokenExchange in the API reference for Kubernetes. The two modes take the same fields; standalone spells the enum values in camelCase, such as jwtBearer rather than JwtBearer.

FieldDescription
host, policiesThe token endpoint, referenced as a backend. A host port of 443 automatically enables backend TLS.
pathPath of the token endpoint on the backend. Must start with /. Defaults to /.
grantTypetokenExchange (default, RFC 8693) or jwtBearer (RFC 7523).
clientAuthClient authentication for the token endpoint: clientSecretBasic (default), clientSecretPost, or privateKeyJwt. Omit the field and agentgateway sends no client authentication. See Authenticate the gateway to the token endpoint.
audiences, scopes, resourcesThe audience, scope, and resource parameters sent to the token endpoint. resources are RFC 8707 resource indicators.
subjectTokenWhere to read the incoming token and its token type. Defaults to the Authorization: Bearer header with token type access_token.
actorTokenOptional RFC 8693 delegation actor token (tokenExchange grant only). Has no default source.
authorizationLocationWhere to place the exchanged token in the backend request. Defaults to the Authorization header with a Bearer prefix.
additionalParamsExtra form parameters appended to the token request. Values are CEL expressions.
cacheIn-memory token cache. Defaults to 8192 entries with a 300-second TTL when the response omits expires_in. Set maxEntries: 0 to disable.
Was this page helpful?
Agentgateway assistant

Ask me anything about agentgateway configuration, features, or usage.

Note: AI-generated content might contain errors; please verify and test all returned information.

Tip: one topic per conversation gives the best results. Use the + button in the chat header to start a new conversation.

Switching topics? Starting a new conversation improves accuracy.
↑↓ navigate ↵ select esc dismiss

What could be improved?

Your feedback helps us improve assistant answers and identify docs gaps we should fix.

Need more help? Join us on Discord: https://discord.gg/y9efgEmppm

Want to use your own agent? Add the Solo MCP server to query our docs directly. Get started here: https://search.solo.io/.