Token transformationv1.0+

Use the OpenID Connect plugin to switch an external token with limited scope for an internal token with necessary scope.

In this example, clients are registered in the same AuthZ server as the one protecting the upstream services. However, clients are restricted and are issued tokens with limited scopes for security reasons. Kong Gateway is a special client that is authorized to request a token (with appropriate scope) to access the upstream services. on behalf of these other clients. Kong exchanges the incoming token for a new token with the right scope to access the upstream services.

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

  • An identity provider (IdPs) that supports token exchange, configured with two clients. Client A is limited in what it can request, while Client 2 is authorized to do token exchange and request specific scopes.

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 (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!