Token exchangev3.14+

Use token exchange to replace the incoming access token with a token issued by a different authorization server or with different scopes before the request reaches the upstream MCP server. This example also includes actor token configuration, which is required by identity providers like Okta that need the original token passed as the actor token during the exchange.

When token_exchange.enabled is true, the plugin:

  1. Validates the incoming Bearer token using introspection or JWKS.
  2. Calls the configured token exchange endpoint with the validated token as the subject token.
  3. Forwards the request to the upstream MCP server with the exchanged token.

Because the plugin is passing a credential to the upstream, passthrough_credentials must be set to true when token exchange is enabled.

Exchanged tokens are cached by default. The TTL comes from the expires_in field in the exchange response, or falls back to token_exchange.cache.ttl if the field is absent.

Environment variables

  • MCP_RESOURCE_URL: Resource identifier for the MCP server (for example, https://api.example.com/mcp).

  • AUTHORIZATION_SERVER_URL: Authorization server URL used to validate the incoming token.

  • INTROSPECTION_ENDPOINT_URL: Token introspection endpoint. Used by Kong Gateway to validate the incoming access token.

  • CLIENT_ID: Client ID used by Kong Gateway when calling the introspection endpoint.

  • CLIENT_SECRET: Client secret used by Kong Gateway when calling the introspection endpoint.

  • TOKEN_EXCHANGE_ENDPOINT_URL: Token exchange endpoint URL (for example, https://exchange.example.com/oauth/token).

  • EXCHANGE_CLIENT_ID: Client ID used by Kong Gateway when calling the token exchange endpoint.

  • EXCHANGE_CLIENT_SECRET: Client secret used by Kong Gateway when calling the token exchange endpoint.

Set up the plugin

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!