Validate bearer tokens on a surface
By the end of this guide, you will have a JWT verification strategy configured and attached to a surface so that the gateway validates bearer tokens on every inbound request.
A JWT verification strategy is a reusable configuration that names a trusted issuer and points to that issuer’s signing keys. Surfaces reference the strategy rather than holding issuer details directly. For background on how strategies fit the gateway’s credential model, see Credentials.
Without a strategy, the surface cannot validate bearer tokens issued by your identity provider.
Use this guide when:
- You need a surface to accept bearer tokens from an identity provider.
- You want multiple surfaces to share the same issuer configuration.
To let standard MCP clients sign users in at your identity provider and fetch the token themselves, follow this guide to create the strategy, then let MCP clients discover your authorization server instead of adding audiences and a deny policy.
Prerequisites
- A running Agent Gateway instance with the dashboard accessible.
- Power User or Administrator role on the gateway.
- The
issuerURL of the identity provider that issues the JWTs, for examplehttps://auth.example.com. - Either the JWKS URI of the identity provider, or the static JWKS JSON if the provider does not publish a discovery endpoint.
- A surface to attach the strategy to.
Steps
Create a JWT verification strategy

In the sidebar, select Credentials, then select the JWT Verification tab. Select Add Strategy.
Fill in the strategy fields:
Field Required Description Name Yes A descriptive label, for example Auth0 production.Expected Issuer Yes The exact issclaim value the JWT must contain. Must match precisely, including the trailing slash if present.JWKS Source Yes How the gateway obtains the public keys. Select Remote URL or Static Keys. For the Remote URL option, enter the JWKS URI, for example
https://auth.example.com/.well-known/jwks.json. The gateway validates the URI is reachable when you save. A green indicator confirms the URI resolved successfully.For the Static Keys option, paste the JWKS JSON directly into the editor. Use this when the identity provider does not expose a JWKS endpoint.
Select Create Strategy.
Reference the strategy on a surface
- Open the surface you want to protect on the canvas.
- From the left-hand palette, drag a Caller Context element onto the surface and drop it between the Access Point and Managed Agent nodes. A surface holds one Caller Context, so if yours already has one, such as the API key element from Create your first surface, select that element instead.
- Select the Caller Context node to open its config panel.
- Under Authentication methods, either select Configure ↗ on the method row, or, to keep an existing method of another type, select Add method › JWT Bearer. Either way, the full configuration editor opens on that method. See Accept JWTs and API keys on one surface.
- In Authentication Method, check that JWT Bearer is selected, the default for a new Caller Context. Changing an existing method’s type replaces that method, and its callers then get
401. - Select your strategy from the JWT Verification Strategy dropdown.
- Optionally, add Accepted Audiences to restrict which tokens are accepted. Type an audience value and press Enter. The JWT must contain at least one of the accepted values in its
audclaim. Leave empty to accept any audience. On an MCP surface with Authorization server discovery on, this list stays empty, because the token’saudmust be the advertised resource URL instead. - Close the editor and select the save icon (tooltip: Save changes) on the canvas.
On a closed Access Point, the default for surfaces created from version 1.0.4, the gateway now refuses a missing or invalid token with 401 before policy runs.
Allow only authenticated callers with a policy
On a public or legacy Access Point, a missing or invalid bearer token is handed to policy rather than refused. Add a Policy element so the surface also denies such a caller if Public access is switched on, or on a surface created before version 1.0.4. See Access Point readiness.
In the left palette, find the Policy element under the Security & Policy category.
Drag Policy onto the canvas and drop it on the same edge as the Caller Context element.
Select the Policy node to open its config panel.
In Policy Definition, select or create a policy with the following rule.
package surface.policy default allow = false allow if { input.source_auth.method == "jwt_bearer" }This allows the request only when the bearer token validated successfully. On a public or legacy Access Point, a missing or invalid token (
input.source_auth.method == "failed") falls through todefault allow = falseand the request is denied. See OPA policies reference for the fullinput.source_authschema.Close the editor and select the save icon (tooltip: Save changes) on the canvas.
Confirm
Replace <ENTRY_POINT_URL> in the commands below with the Entry point URL shown at the top of the surface canvas.
Test 1: valid token is accepted
Send a request with a valid JWT bearer token to the surface:
curl -k -X POST "<ENTRY_POINT_URL>" \
-H "Authorization: Bearer <YOUR_JWT_TOKEN>" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"message/send","id":1,"params":{}}'Expected: the gateway accepts the request and forwards it to the surface.
The -k flag disables TLS certificate verification. Use this for local testing only. Remove it in production.
Test 2: missing token returns 401
Send the same request without the Authorization header:
curl -k -X POST "<ENTRY_POINT_URL>" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"message/send","id":1,"params":{}}'Expected: 401 Unauthorized with a WWW-Authenticate: Bearer header and the detail “Caller credential missing or invalid”. The gateway refused the caller before policy ran.
The -k flag disables TLS certificate verification. Use this for local testing only. Remove it in production.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
A request without a token returns 200 instead of 401. | The Access Point is public (Public access is on) or legacy, so a failed validation reaches policy, and no policy denies it. | Switch off Public access, or select Close Access Point in the legacy notice, and save. Alternatively, add the Policy element from the policy step, with a rule that only allows when input.source_auth.method == "jwt_bearer". |
| JWKS URI validation fails on save | The URI is unreachable from the gateway’s network. | Confirm the URI is publicly accessible and the gateway has outbound HTTP access to it. |
Valid tokens return 401 | The iss claim in the token does not match Expected Issuer exactly. | Decode the token locally (for example cut -d. -f2 <<< "$TOKEN" | tr '_-' '/+' | base64 -d 2>/dev/null) or with your identity provider’s token viewer, and compare its iss claim with Expected Issuer. Check for trailing slash differences. |
Tokens return 401 although issuer and signature are correct | The token’s aud claim does not match the configured accepted values. | Either update the accepted audiences list or remove it to accept any audience. |
| A freshly issued token is refused, then accepted a minute or two later. | The token’s nbf (not before) time is more than 60 seconds ahead of the gateway’s clock, so the gateway treats it as not yet valid. | Check that the identity provider’s clock is correct, and that it sets nbf to the issue time rather than a later time. |
| No strategies appear in the JWT Verification Strategy dropdown | No strategies have been created yet. | Create at least one strategy first, then return to the surface and open the Caller Context fullscreen editor again. |
Next steps
- Apply OPA policies to your gateway and surfaces: write OPA Rego rules that use verified JWT claims as enforcement conditions.
- Limit surface access by agent identity: derive a stable agent DID from the authenticated identity.
- Accept JWTs and API keys on one surface: add an API key method for partner agents beside the JWT Bearer method.
- Enable authorization server discovery for MCP clients: let MCP clients sign users in at your identity provider and fetch tokens for an MCP surface.
Related
- Credentials: conceptual overview of JWT verification strategies and how they fit the credential model.
- Secrets: store credentials for upstream services.
- JWT Verification Strategies: strategy fields and every check in the token validation sequence.
Glad to hear it. Thanks for letting us know.
Sorry to hear that. Thanks for letting us know.
Still stuck? Ask the community on Discord or contact us.