Learn

Access tokens (JWT)

Require a valid bearer token (JWT) on a route. The gateway validates it before the request reaches your API.

Access tokens (JWT)

Setting it up

  1. Register the identity provider on the Identity providers page.

  2. Open the route editor → Token → Require an access token:

    • Provider: the identity provider you registered
    • Audiences: the API's application ID URI (e.g. api://shop); enter multiple if unsure (Entra v1 and v2 tokens carry different forms)
    • Scopes (optional): every request must have these scopes
    • Roles (optional): every request must have one of these app roles
    • Required claims (optional): e.g. tid = <your tenant ID> to prevent tokens from other tenants
    • Paths without a token (optional): e.g. /health
  3. It starts in Log only: the request log (view Token) shows what would be refused and why.

  4. Use Test a token: paste a real token to see what it contains and whether it passes.

  5. Switch to Enforce when the log is quiet.

What clients get

  • No token or invalid token: 401 with WWW-Authenticate: Bearer error="invalid_token"
  • Valid token but missing required scope/role: 403 with insufficient_scope
  • Provider keys never read: 503

Clients never get the reason for a 401 or 403 — only the request log shows it.

Passing claims to the backend

Under Claims for the backend, map claim names to header names:

  • X-User-Id = oid → adds X-User-Id: <oid value> to the forwarded request
  • X-User-Email = preferred_username

The gateway always removes these headers from what clients send first, so they cannot be forged.

Tick Remove the token to strip the Authorization header before forwarding.

Per-user rate limiting

A rate limit can count per signed-in user (the token's sub claim) instead of per address. Useful for per-user quotas on an API.

Example: protecting an API with Entra ID tokens

Clients get a token from Entra ID for api://shop. The gateway validates it.

  1. Register the provider: issuer = https://login.microsoftonline.com/<tenant>/v2.0, name = entra.
  2. Route editor → Token → Require an access token: provider = entra, audience = api://shop, required claim tid = <tenant ID>.
  3. Log only for a week. The log is quiet.
  4. Switch to Enforce.

Requests without a token get 401. Requests with a token for a different tenant get 401 (wrong claim). Requests with a token for the right tenant pass.