Token exchange with an actor tokenv3.16+

Use the OpenID Connect plugin to include an actor token in a token exchange request, representing the identity of the party acting on behalf of the subject. This is useful for delegation scenarios, such as a backend service or AI agent acting on behalf of a user, and is required by identity providers (such as Okta) that expect an actor token during certain token exchange grants.

In this example, Kong Gateway reads the actor token from a request header and includes it in the token exchange request along with the subject token.

Here’s how token exchange works with the OIDC plugin:

 
sequenceDiagram
    participant C as Client
(e.g. mobile app) participant K as API Gateway
with OIDC plugin participant A as Authorization server
(e.g. Keycloak) participant U as Upstream
(backend service,
e.g. httpbin) C->>K: Request with subject token activate K note over K: Validate subject token
(iss, exp, nbf) K->>A: Token exchange request activate A A-->>K: Exchanged access token deactivate A K->>K: Validate exchanged token K->>U: Proxy request with exchanged token activate U U-->>K: Response deactivate U K-->>C: Response deactivate K

For more detail on token exchange support, see the Token exchange reference.

Prerequisites

  • An identity provider that supports token exchange and accepts an actor token during the exchange.

Environment variables

  • ISSUER: The issuer authentication URL for the authorization server that issued the token in the incoming request. For example, if you’re using Keycloak as your IdP, the issuer URL looks like this: http://localhost:8080/realms/example-realm.

  • CLIENT_ID: The client ID that the plugin uses when it calls authenticated endpoints of the IdP.

  • CLIENT_SECRET: The client secret needed to connect to your IdP.

  • ACTOR_TOKEN_HEADER: The name of the request header that carries the actor token, for example X-Actor-Token. The client or an upstream service must set this header on the incoming request for Kong Gateway to include it in the exchange.

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!