Skip to main content

Validate JWT Tokens

Require a valid access token on every request, issued by an auth gateway of the environment or by your own identity provider.

How it works​

The caller sends a signed token; the gateway verifies its signature with the public keys of the issuer, then its issuer, expiry and (when asked) audience. No call is made to the issuer per request, so verification is fast and keeps working if the issuer is briefly unavailable.

Turn the audience check on

Without it, a token issued for another API by the same issuer is accepted here.

Every parameter and its default: reference.

Use cases​

For APIs called by applications. A token expires and names the API it is for, which a key does not.

Prerequisites​

Procedure​

  1. In API Manager, go to API Instances and open the API. To cover everything published on a gateway instead, open the gateway.
  2. Open its Security policies and add the rule token verification (JWT).
  3. In Tokens issued by, choose An auth gateway, then the auth gateway. For your own provider, choose Another identity provider and fill Provider Name, Issuer and JWKS URI.
  4. Turn Check the audience on. Audience of this API is filled in for you.
  5. Add Other audiences only if tokens meant for something else must also be accepted.
  6. Deploy.

Parameters​

FieldWhat it isDefault
Tokens issued byAn auth gateway of the environment, or another identity provider.Another identity provider
Auth gatewayThe auth gateway whose tokens are accepted. Its issuer and the address of its keys come with it.—
Provider NameA short name for the source of tokens, such as internal-sso.—
IssuerThe issuer written in the tokens. It must match exactly.—
JWKS URIThe address where the provider publishes its public keys.—
Check the audienceRefuse a token that was not issued for this API.Off
Audience of this APIThe audience ID of the API. A token is checked against it first.Filled in
Other audiencesOther values a token may be intended for.—

Verification​

Obtain a token, then call the API
TOKEN=$(curl -s -u "<client-id>:<secret>" https://auth.example.com/api/oidc/token \
-d grant_type=client_credentials -d scope="orders.read" | jq -r .access_token)

curl -i -H "Authorization: Bearer $TOKEN" https://orders.example.com/orders
Answer
HTTP/1.1 200 OK

Behavior and limits​

  • With Check the audience off, any valid token of the issuer is accepted, whatever API it was meant for.
  • A change in a list of clients takes a couple of minutes to reach the auth gateway; a token obtained before the change does not carry it.

See also​