Skip to content
GatewayMarkdown

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.

  • 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, SCOPES and DPOP_REQUIRED change what a refusal offers: see Gateway configuration.

A client calls your API through the gateway with its token:

GET /orders/42 HTTP/1.1
Host: api.example.com
Authorization: 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 Unauthorized
WWW-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.

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.

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.

  • 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.
WhatDefaultCan it change?
The verified caller’s headerx-agent-idNo
Challenges on a missing tokenBearer and DPoPDPoP alone with DPOP_REQUIRED
Scopes the metadata namesNoneSCOPES
Proof algorithms offeredES256, PS256, RS256No
Status and reasonWhat it means
400 path_not_canonicalThe path has dot segments, empty segments, a backslash or an encoding your API might decode differently
401 missing_tokenNo token. Both Bearer and DPoP are offered (DPoP alone with DPOP_REQUIRED)
401 invalid_tokenThe token doesn’t verify, isn’t for this API, or isn’t presented as its binding requires
401 invalid_dpop_proofA bound token’s proof is missing or doesn’t hold: see Bound tokens at the gateway
401 use_dpop_nonceThe proof needs a fresh nonce, given in DPoP-Nonce
401 token_revokedThe 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_revokedIts agent, or an agent acting in it, was stopped, or the user took that agent back
401 insufficient_user_authenticationA stronger or more recent sign-in would pass, with the acr_values or max_age needed
403 no_policies_loadedThe gateway holds no policies for this request
403 policies_excludedA 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_policyA policy refuses the request, or none allows it
403 upstream_unavailableThe realm had to decide and couldn’t be asked
403 exchange_refusedWith UPSTREAM_AUDIENCE, the realm refused to swap the caller’s token. A 503 means it couldn’t be asked
503 revocations_staleThe revocation list hasn’t been refreshed for three intervals: see Fails closed
503 dpop_proofs_fullThe gateway is holding too many recent proofs. Try again shortly
502, 503, 504Allowed, 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.

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.

A refusal you didn’t expect is in Troubleshooting, by its status and reason.