Token exchange for cross-domain securityv1.0+

Use the OpenID Connect plugin to exchange tokens between different authorization servers or identity providers (IdPs). This is useful when you have APIs protected by different authorization servers, but you want to allow clients to access all of them with a single token.

In this scenario:

  1. The client is issued a token from AuthZ Server A.
  2. APIs are protected by AuthZ Server B.
  3. The OIDC plugin is configured to exchange tokens from Server A with Server B.

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

Prerequisites

  • Two configured identity providers (IdPs) that support token exchange. This can be two separate IdPs, such as Okta and Keycloak, or two AuthZ servers (Server A, Server B) in the same IdP.

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.

  • SUBJECT_TOKEN_ISSUER: The issuer authentication URL for the authorization server that you want to exchange tokens with.

  • CLIENT_ID: The client ID that the plugin uses when it calls authenticated endpoints of the IdP (in this case, Server A).

  • CLIENT_SECRET: The client secret needed to connect to your IdP (in this case, Server A).

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!