Requests and refusals
What a caller sees when the gateway refuses it, how a client finds where to sign in, and what your API receives when a request is allowed.
AvailableAPIRFC 6750, RFC 9728, RFC 9470
With the gateway in front of your API, a refused request never reaches it, and the refusal
tells the caller what would help: where to get a token, which scopes would pass, or that a stronger sign-in is needed.
A client that has never met your API can find its way from the first 401 to a working token without anything
configured by hand. An allowed request reaches your API with the verified caller named in a header.
Before you begin
Section titled “Before you begin”- The gateway running in front of your API: see Run the gateway. Its image isn’t published yet: ask your Cvyūh contact for it.
- Nothing to set in the realm. On the gateway,
SCOPESandDPOP_REQUIREDchange what a refusal offers: see Gateway configuration.
How it works
Section titled “How it works”What callers see
Section titled “What callers see”A client calls your API through the gateway with its token:
GET /orders/42 HTTP/1.1Host: api.example.comAuthorization: Bearer eyJhbGciOiJFUzI1NiIsInR5cCI6ImF0K2p3dCJ9.eyJzdWIiOiI…A request with no token is refused, and the answer offers both ways to present one, with the address of the API’s metadata:
HTTP/1.1 401 UnauthorizedWWW-Authenticate: Bearer resource_metadata="https://api.example.com/.well-known/oauth-protected-resource"WWW-Authenticate: DPoP algs="ES256 PS256 RS256", resource_metadata="https://api.example.com/.well-known/oauth-protected-resource"A token the policies don’t allow is 403, with an insufficient_scope challenge naming the scopes that would pass
where a policy says so. A request a stronger or more recent sign-in would pass is
401 insufficient_user_authentication, with the acr_values or max_age needed, so the app can ask the user to step up: see
Step-up and re-authentication.
Resource metadata
Section titled “Resource metadata”The metadata address in every challenge is public, and names the realm that protects the API:
{ "resource": "https://api.example.com", "authorization_servers": ["https://foobar.cvyuh.com/oauth2"], "bearer_methods_supported": ["header"], "dpop_bound_access_tokens_required": false, "dpop_signing_alg_values_supported": ["ES256", "PS256", "RS256"], "scopes_supported": ["orders:read"]}resource is your API’s audience, and scopes_supported appears only when you give the gateway the scopes to name
(SCOPES, in Gateway configuration). When the
audience has a path, such as https://gw.example.com/mcp, the metadata is at
/.well-known/oauth-protected-resource/mcp.
What your API sees
Section titled “What your API sees”The request, at your API’s own address, with x-agent-id set to the token’s sub: the user, agent or client the
token is about. A client can’t set that header itself; any it sends is removed. With
token swap on, the request also carries a fresh token meant for your API in place of the
caller’s.
Good to know
Section titled “Good to know”- Paths are decided as your API reads them. A path your API might read differently is refused
(
400 path_not_canonical), so an escaped letter can never reach a path a policy denies. - The host is your API’s. A request is decided on the host and port it will be forwarded to, never the one the client named.
Limits and defaults
Section titled “Limits and defaults”| What | Default | Can it change? |
|---|---|---|
| The verified caller’s header | x-agent-id | No |
| Challenges on a missing token | Bearer and DPoP | DPoP alone with DPOP_REQUIRED |
| Scopes the metadata names | None | SCOPES |
| Proof algorithms offered | ES256, PS256, RS256 | No |
Reference
Section titled “Reference”Errors
Section titled “Errors”| Status and reason | What it means |
|---|---|
400 path_not_canonical | The path has dot segments, empty segments, a backslash or an encoding your API might decode differently |
401 missing_token | No token. Both Bearer and DPoP are offered (DPoP alone with DPOP_REQUIRED) |
401 invalid_token | The token doesn’t verify, isn’t for this API, or isn’t presented as its binding requires |
401 invalid_dpop_proof | A bound token’s proof is missing or doesn’t hold: see Bound tokens at the gateway |
401 use_dpop_nonce | The proof needs a fresh nonce, given in DPoP-Nonce |
401 token_revoked | The token, a token it was exchanged from, its family, its session or its client grant was revoked, or it was issued before its subject or an actor was revoked |
401 agent_revoked | Its agent, or an agent acting in it, was stopped, or the user took that agent back |
401 insufficient_user_authentication | A stronger or more recent sign-in would pass, with the acr_values or max_age needed |
403 no_policies_loaded | The gateway holds no policies for this request |
403 policies_excluded | A policy in the set is incomplete, so the realm left it out, and the set allows nothing until it’s fixed |
403 policy_denied, 403 no_matching_policy | A policy refuses the request, or none allows it |
403 upstream_unavailable | The realm had to decide and couldn’t be asked |
403 exchange_refused | With UPSTREAM_AUDIENCE, the realm refused to swap the caller’s token. A 503 means it couldn’t be asked |
503 revocations_stale | The revocation list hasn’t been refreshed for three intervals: see Fails closed |
503 dpop_proofs_full | The gateway is holding too many recent proofs. Try again shortly |
502, 503, 504 | Allowed, but your API failed, refused the connection, or didn’t answer within 60 seconds |
On an MCP path (MCP tool calls), a 403 carries its reason as a JSON-RPC error, with the same status and
challenge.
Audit record
Section titled “Audit record”The gateway’s refusals aren’t on the audit trail yet. Each is a warning line in the gateway’s own log, with the path,
the caller when the token verified, and the reason: see Logs and tracing.
A decision the gateway asks the realm for is on the trail as POLICY_DECIDED.
Troubleshooting
Section titled “Troubleshooting”A refusal you didn’t expect is in Troubleshooting, by its status and reason.
Related
Section titled “Related”- Run the gateway: how each request is checked, and its settings.
- Step-up and re-authentication: asking the user for a stronger sign-in.
- Get started with Gateway: an allowed and a refused call, end to end.