What you will have at the end
Two Routes that only answer a request carrying a valid access token. accounts-api accepts a JWT the caller signs itself, verified by jwt-auth against a secret stored on the Consumer’s credential. ledger-api accepts an OAuth 2.0 access token issued by Keycloak to a machine client, verified by openid-connect in bearer-only mode, first against the provider’s published keys and then by asking the provider about each token. A missing, expired or tampered token is answered 401 and a token for another audience 403, before the backend is called. Every call is a request record in Traffic Explorer, the refusals with gateway as the Upstream node, and both Plugin additions are in the audit log with their secrets masked.
Prerequisites
- An identity provider that speaks OpenID Connect. This article uses the lab Keycloak from Keycloak and G8, realm
corp, reachable from the gateway atlocalhost:8190. Microsoft Entra ID or any other provider takes the same form with its own discovery URL; nothing below is specific to Keycloak except the addresses. - Two clients in the realm:
payments-gateway, the API the tokens are meant for, andbatch-job, the machine caller, with service accounts enabled and an audience mapper that putspayments-gatewayinto the tokens it receives. A token without that audience is the refusal shown later. - A backend. Here it is
httpbin-backend, an Upstream with the nodehttpbin:8080, a service that echoes the request it receives, so the article can show what the backend sees. - Two Routes to the Upstream:
accounts-apion/accounts/*andledger-apion/ledger/*, each withproxy-rewritesending the path to the echo service’s/anything/endpoint. - A Consumer for the batch job,
batch_job, with no credential yet. - Traffic logging turned on under Traffic Explorer › Settings, and a role that may manage Routes and Consumers. The screenshots below were taken as
nora.becker.
Two ways to accept a token
An access token reaches the gateway in the Authorization: Bearer header either way. The difference is who holds the key that proves it is genuine.
With jwt-auth, the key is on the Consumer’s credential: a shared secret for the HS algorithms, or a public key for RS, ES, PS and EdDSA. The caller signs its own tokens and the gateway verifies them without talking to anyone. This is the shape for a job or a partner system you hand a key to.
With openid-connect in bearer-only mode, the key belongs to the identity provider. The gateway reads the provider’s discovery document and verifies each token against the published keys, or, for providers that issue opaque tokens, sends each token to the introspection endpoint and lets the provider answer. This is the shape for OAuth 2.0 clients that get their tokens from the provider.
Part one: a JWT the caller signs
The credential on the Consumer
Open the Consumer batch_job, select Credentials and Add credential. The Credential ID is batch-job-jwt. Under Authentication, choose jwt-auth as the Plugin, and the credential’s own fields appear:
- Key:
batch-job. The form says what it is: the key claim the token carries. The gateway reads this claim from the token and looks the credential up by it. - Algorithm:
HS256, the default. The form then asks for a Secret, the shared secret the caller signs with, stored on the engine and shown only to roles that manage the Consumer. With RS256 or another asymmetric algorithm it asks for a Public key instead, and the caller keeps the private half. - Base64 secret stays off; the secret is used as typed. Grace period stays at 0.

•••• once saved.
Select Create credential. The credential page shows the Plugin, the Key and the Secret as •••• with a Show control for roles that may see it; the audit log has a credential.created entry whose masked value changed is plugins.jwt-auth.secret.
The Plugin on the Route
Open the Route accounts-api, select Plugins, Add plugin, and choose jwt-auth from the catalog. Two settings matter here:
- Basics › Claims to verify: tick
exp. The form says it in one sentence: a token without a ticked claim is refused. A token without an expiry would otherwise be valid for ever. - Basics › Hide credentials: on. The token is checked at the gateway and removed before the request reaches the backend, which then sees who the caller is without ever holding the token.
Behavior › Header, Query and Cookie are where the gateway looks for the token: authorization, jwt and jwt by default. Anonymous consumer stays empty; the note under it explains what happens when it names a Consumer, a request with no credential passes as that Consumer instead of being refused.

Select Add plugin. The Route update is in the audit log with the jwt-auth block as the difference.
What a client sees
The batch job signs a token with the secret: the header {"alg":"HS256"}, the claims key, exp and iat, and the HMAC signature. With a valid token:
curl -i -H "Authorization: Bearer $TOKEN" http://localhost:9281/accounts/balance
HTTP/1.1 200 OK
The echo service shows what reached it: no Authorization header, and two headers the gateway added once it knew the caller.
"X-Consumer-Username": ["batch_job"],
"X-Credential-Identifier": ["batch-job-jwt"]
A token whose exp is in the past, a token with a key that matches no credential, and no token at all are refused by the gateway with the reason in the body and the realm in the WWW-Authenticate header:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="jwt"
{"message":"failed to verify jwt"}
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="jwt"
{"message":"Invalid user key in JWT token"}
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="jwt"
{"message":"Missing JWT token in request"}
A token with one character changed in its signature gets the same failed to verify jwt.
Part two: an access token from the identity provider
The token
The batch job asks Keycloak for a token with the client credentials grant:
curl -s -X POST http://localhost:8190/realms/corp/protocol/openid-connect/token \
-d grant_type=client_credentials -d client_id=batch-job -d client_secret=$SECRET
The answer carries access_token, expires_in and token_type: Bearer. Decoded, the token’s aud claim is ["payments-gateway", "account"] and its azp is batch-job: it was issued to the batch job for the payments API.
The Plugin on the Route
Open the Route ledger-api, Plugins, Add plugin, openid-connect. Under Basics:
- Discovery:
http://localhost:8190/realms/corp/.well-known/openid-configuration. The engine reads the provider’s endpoints and keys from it. - Client ID
payments-gatewayand its Client secret, which is stored on the engine and shown only to roles that manage the Route. The client ID is also what the audience check below compares against. - Bearer only: on. The Session section disappears from the form, because a bearer-only Route never sends a browser to sign in and never sets a cookie; a request without a token is answered 401.

Under Behavior:
- Use jwks: on. The form says what it changes: the token is verified with the provider’s published keys instead of asking the provider about each one. Leave it off and set an Introspection endpoint for a provider whose tokens are opaque; the article does that below.
- Claim validator › Audience: Required on and Match with client ID on. A token whose
audclaim does not carrypayments-gatewayis refused, which is how a token issued for another API is kept out even though the same provider signed it.

One more field sits under Advanced: Realm, the value the gateway puts in the WWW-Authenticate header of a refusal. Set it to ledger-api so the header names the API; the default is a generic value. Select Add plugin. The audit record of the Route update lists the Plugin block with client_secret as ••••.
What a client sees
With the batch job’s token:
curl -i -H "Authorization: Bearer $ACCESS_TOKEN" http://localhost:9281/ledger/entries
HTTP/1.1 200 OK
The echo service received the Authorization header, an X-Access-Token header and an X-Userinfo header; decoded, the userinfo names service-account-batch-job as the caller. Which of these the backend gets is a setting each: Set access token header, Set userinfo header and Set ID token header under Behavior.
A token Keycloak issued to payments-gateway itself, whose audience is only account, is refused:
HTTP/1.1 403 Forbidden
{"error":"mismatched audience"}
No token at all:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="ledger-api"
An expired token is refused with the provider’s wording in the header:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="ledger-api", error="invalid_token", error_description="JWT expired"
One measurement to know about: the batch job’s tokens were issued with a 90-second lifetime for this article, and a token was still accepted 13 seconds after its expiry and refused 138 seconds after it. That is consistent with the 120-second default of Advanced › Iat slack, the tolerance for clock skew between the engine and the provider; the exact boundary was not measured.
Asking the provider instead: introspection
For a provider whose access tokens are opaque strings, the gateway cannot verify anything itself. Edit the Plugin, switch Use jwks off and set Introspection endpoint to the address from the discovery document, http://localhost:8190/realms/corp/protocol/openid-connect/token/introspect; the client ID and secret above are the credentials the gateway introspects with. Save.
The three calls answer the same way, 200, 403 for the wrong audience and 401 for a token the provider does not know, and the provider’s log now shows an introspection request for each refusal, because the decision was its own:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="ledger-api", error="invalid_token", error_description="invalid token"
Introspection costs a call to the provider per request; jwks costs one fetch of the keys, which the engine then keeps. Prefer jwks when the tokens are JWTs.
What Traffic Explorer shows
Every call above is a request record. Open Observe › Traffic Explorer and search for the path. The accepted calls show the backend’s address as the Upstream node; the 401s and the 403 show gateway, because the engine answered them itself and no request reached the backend.

The same view for /accounts/balance lists the jwt-auth calls, with batch_job beside the Route name on the accepted ones, because jwt-auth names the Consumer and the bearer-only openid-connect does not. The Route’s Analytics tab counts the same calls by status class.
What the audit log keeps
Adding openid-connect to ledger-api is a Route update: who, when, which Route, and the configuration before and after. The client_secret is •••• on the after side, and the record says so under the diff: a masked value changed, plugins.openid-connect.client_secret. The credential on batch_job has its own entry with plugins.jwt-auth.secret masked the same way, and the later switch to introspection is a third entry.

What to do next
- Put the identity in front of a browser as well: Keycloak and G8 adds the sign-in flow and Keycloak authorization on the same Plugin.
- The identity options side by side, with the Plugin behind each, are in the capabilities reference and on API Security; the solution page is API security and identity.
- The other two identities a Route can ask for: a directory password, Directory accounts as API callers, and a client certificate, Mutual TLS at the gateway.
- Limit each caller once it is known: Rate limiting per Consumer.