Route requests to different upstreams based on the authenticated callerv3.14+

Map an authenticated credential to a named Upstream entity and override the backend per request. This example works together with the OpenID Connect plugin, which validates a bearer token and extracts a token claim (such as client_id) as a virtual credential. Datakit then reads that credential and uses its value to select an upstream.

This example contains the following nodes:

  1. GET_CREDENTIAL reads the kong.client.credential object that the OpenID Connect plugin populated.
  2. PICK_UPSTREAM uses a jq map to look up the credential’s .id field and return the matching upstream name. Unknown callers fall through to upstream-default.
  3. SET_UPSTREAM writes the resolved upstream name to kong.service.upstream, overriding the backend for this request.

For a complete tutorial, see Route requests to different upstreams based on the authenticated caller.

Note: The OpenID Connect plugin has a higher static priority than Datakit, so it always runs first in the access phase. No explicit plugin ordering configuration is required.

Prerequisites

  • You have configured the OpenID Connect plugin with credential_claim pointing to a token claim (such as client_id) and consumer_optional: true.

  • You have created named Upstream entities for each caller and a fallback upstream.

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!