Skip to content

Security and governanceGuide

MCP authorization: what a gateway must do with OAuth tokens

A gateway in front of remote MCP servers sits where OAuth tokens are issued, validated and, if you are careless, forwarded. This guide walks through what the draft MCP authorization spec requires of that layer, how to choose between per-user and shared upstream credentials, and which audit records to keep.

By INFRO Editorial

Published

10 min read

A grid of dark glass cards with small bar charts, a few of them lit amber, on a dark ground

In short

A gateway that fronts remote MCP servers must act as a resource server: validate that each token was issued for the gateway's own resource, never forward it upstream, and use a separate upstream credential 5. Choose per-user or shared upstream credentials deliberately, and log enough to tie every tool call to a person, a client and a scope.

Key takeaways

  • A gateway that fronts MCP servers is an OAuth resource server to its clients: it must accept only tokens issued for its own resource and reject the rest.
  • Token passthrough is forbidden: the token a client sends to the gateway is never the token used upstream, which is a separate credential from the upstream authorization server.
  • Per-user upstream credentials keep the upstream's own authorization decisions tied to a person; shared credentials are simpler but make the gateway the only place identity is enforced.
  • Scopes are challenged per request and widened by step-up; the gateway should log the scope each call ran under, not only the outcome.
  • Keep records that bind person, client, audience, scope, tool and outcome, and never store the tokens themselves.

Where a gateway sits in the MCP authorization flow

The draft MCP specification defines authorization at the transport level for HTTP-based transports. A protected MCP server is an OAuth 2.1 resource server, the MCP client is an OAuth client acting for a resource owner, and a separate authorization server authenticates the user and issues the tokens 1. Authorization is optional, and the stdio transport is meant to take credentials from the environment instead 1.

Put a gateway in front of remote MCP servers and you have to decide which of those roles it plays. For the clients connecting to it, the gateway is the MCP server, so it is the resource server: it must publish protected resource metadata, challenge unauthenticated requests, and validate tokens. For each upstream server it is a client of something else, and that relationship needs its own credential. Most of the mistakes in this area come from collapsing those two relationships into one token.

The rest of this guide takes the flow in order: discovery, audience, scopes, the passthrough rule, upstream credentials, and the records worth keeping. It complements the credential-leak article and the gateway overview, and does not repeat their material. The spec text is a draft as read on 2026-11-18, so recheck normative wording before you encode it in policy.

What the client does before your gateway sees a token

A client that connects with no token gets a 401. The server must either put a resource_metadata URL in the WWW-Authenticate header or serve its metadata at a well-known URI, and clients must support both 2. That metadata is the OAuth 2.0 Protected Resource Metadata document from RFC 9728, which MCP servers must implement 1. In it, resource is required and scopes_supported is recommended; authorization_servers lists the issuers 3. The MCP document must include authorization_servers with at least one entry 2.

A minimal document for a gateway endpoint looks like this:

/.well-known/oauth-protected-resource/mcp
{
  "resource": "https://mcp-gw.example.com/mcp",
  "authorization_servers": ["https://auth.example.com"],
  "scopes_supported": ["mcp:tools"]
}

The resource value should be the exact URL clients connect to, and clients must not use a document whose resource does not match 4. That binding is what stops an attacker from publishing metadata that claims to describe your gateway. RFC 9728 derives the well-known location deterministically from the resource URL for that reason 3.

The client then fetches authorization server metadata, checks that the issuer equals the issuer used to build the URL, and refuses to continue if code_challenge_methods_supported is absent, because that means no PKCE 5. If your gateway lists several authorization servers, each is independent: clients keep separate registration state and tokens per server 2. Your gateway should do the same when it validates, keeping a per-issuer key set and never accepting an issuer not in its list.

Audience: the check that makes a token yours

Clients must send the RFC 8707 resource parameter in both the authorization and token requests, set to the MCP server's URL 5. This binds the token to its intended audience. The server side of that bargain is a MUST: MCP servers must validate that tokens presented to them were issued for them, and must reject tokens that do not name them in the audience claim or otherwise prove they are the intended recipient 5.

For a gateway, that check runs on every request, before routing, before any tool lookup. A sketch:

gateway_auth.py
def authenticate(request, cfg):
    token = bearer_token(request.headers)           # Authorization header only
    if token is None:
        return challenge(401, scope="mcp:tools")    # WWW-Authenticate + resource_metadata
    claims = verify(token, issuers=cfg.issuers)     # signature, exp, iss against a per-issuer key set
    if cfg.resource not in as_list(claims["aud"]):
        return challenge(401)                       # token was minted for someone else
    granted = set(claims.get("scope", "").split())
    if not granted >= required_scopes(request):
        return challenge(403, error="insufficient_scope",
                         scope=" ".join(required_scopes(request) | granted))
    return Principal(sub=claims["sub"], client=claims.get("client_id"), scopes=granted)

If your authorization server issues opaque tokens, introspect them and apply the same audience rule to the introspection result; the principle does not depend on the token format. Whatever the format, compare the audience to your own resource identifier by exact match, not by prefix. A gateway that serves many upstream servers under one hostname should decide whether it has one audience for the whole gateway or one per upstream endpoint, and then publish metadata for each accordingly. One audience per gateway is simpler; per-upstream audiences narrow the damage if a token leaks.

Scopes, challenges and step-up

Servers should include a scope parameter in the WWW-Authenticate header to name what the current request needs. Clients must treat the challenged scopes as authoritative for the current operation, and when re-authorizing should include them alongside scopes already granted so permissions needed elsewhere are not lost 1. The selection order for a client is: scopes from the 401 challenge, else everything in scopes_supported, else no scope parameter at all 1. scopes_supported is meant to be the minimal set for basic functionality, with more requested incrementally 1.

A valid token that lacks a scope should get a 403 with an insufficient_scope challenge, which starts step-up authorization; clients should limit how often they retry 4. For a gateway, three consequences follow:

  • Define scopes at a granularity you can enforce at the gateway: for example read-only tool classes versus tools that change state, rather than one scope for everything.
  • Compute required_scopes from the tool definition you have approved, not from what the client claims it is calling.
  • Record the scope set a call ran under. A step-up changes what a session can do; the log should show when.

Over-broad scopes are the usual finding in review, so keep the baseline small. The MCP best-practices page has a dedicated scope minimization section on this risk 6.

Token passthrough: why the gateway cannot just forward

The best-practices page defines token passthrough as an anti-pattern in which an MCP server accepts tokens from a client without validating that they were issued to it, and passes them through to the downstream API 6. The authorization spec states the rule for the upstream leg directly: if the MCP server calls upstream APIs it may act as an OAuth client to them, the token used there is a separate token issued by the upstream authorization server, and the server must not pass through the token it received from the MCP client 5.

For a gateway, that rules out the shortcut of copying the inbound Authorization header onto the upstream request. The shortcut feels harmless because it keeps the user's identity flowing. It breaks audience binding (the token was minted for the gateway, and now an upstream sees it), and it hands every upstream operator a credential that works against the gateway. A related failure: a gateway that logs or caches inbound tokens. The spec calls out tokens cached or logged on the server as a theft route, and asks for short-lived access tokens and refresh-token rotation for public clients 5. Strip the header from your own logs at the edge.

There is a second hazard if the gateway itself brokers upstream OAuth. A proxy that uses one static client ID with a third-party authorization server, lets clients register dynamically, and skips per-client consent is open to the confused deputy attack: a consent cookie from an earlier legitimate login lets an attacker's crafted request skip the consent screen and receive an authorization code 6. The required mitigation is a per-user registry of approved client IDs checked before the third-party flow, exact redirect URI matching and single-use, short-lived state values 6. Dynamic Client Registration is deprecated as of protocol version 2026-07-28, though the attack still applies to proxies that support it 6.

Per-user or shared upstream credentials

Once the gateway has validated the inbound token and refused to forward it, it needs something to present upstream. There are two shapes, and they trade identity fidelity against operational weight.

Per-user upstream tokenShared service credential
Who the upstream seesThe personThe gateway's service identity
Upstream's own permissionsApply per personApply to everyone equally
Where identity is enforcedUpstream and gatewayGateway only
Consent and consent recordsNeeded per user and clientOne admin decision
Storage burdenRefresh tokens per user, rotatedOne secret per server
OffboardingRevoke the user's grantRotate the shared secret or remove the grant at the gateway
FitsMail, documents, tickets where data is user-specificInternal tools, read-only data, automation with no human
Per-user versus shared upstream credentials at a gateway. This comparison is analysis, not spec text.

Per-user tokens are the right default when the upstream holds user-specific data, because the upstream's own access control stays in play and its logs name the person. The MCP tutorial lists user-specific data and the need to audit who performed which actions among the reasons authorization is strongly recommended 4. The cost is a token vault with refresh handling and the consent machinery from the previous section.

A shared credential is simpler, and sometimes the only option when an upstream accepts only an API key. The price is that the upstream cannot tell users apart, so every authorization decision rests on the gateway: which key may call which tool, with which arguments. Use read-only credentials where you can, and treat the gateway's grants as the access-control system of record. Do not mix the two silently. If a server is registered with a shared credential, the audit record should say so, so that a reviewer does not assume the upstream enforced per-person limits.

What INFRO's MCP gateway does with credentials

INFRO's MCP gateway uses the shared-credential shape. An admin registers each server once with its credential; agents then reach it with the INFRO gateway key they already use for model calls, and INFRO adds the server's credential from its vault on every call 7. Server header values are encrypted at rest and bound to the organization and the server; the console and management API show only header names, and replacing a credential is write-only 8. The server never sees the INFRO key, the agent's Authorization header or any X-INFRO-* header 8. INFRO never executes a tool 7.

Two limits matter for this topic. The gateway key is INFRO's own credential, not an MCP-spec OAuth access token, so the audience and step-up rules above describe what to ask of any OAuth-based layer, not a property of that key. And the security model page describes credential headers registered by an admin; it does not describe a per-user upstream OAuth exchange, so check the docs before assuming one. For approved tools, per-key grants and the call record, read the MCP gateway docs (opens in a new tab).

The audit evidence to keep

The records worth keeping are the ones that let you answer, months later, who caused a tool call and under what authority. For each call, keep:

  1. The principal: the sub from the validated token, or the gateway key and its owner.
  2. The client: the OAuth client_id, and for client ID metadata documents the document URL.
  3. The issuer and the audience the token carried, to show the audience check passed.
  4. The scope set in force, and any step-up event with its old and new scope sets.
  5. The upstream server, the tool name and the approved definition version.
  6. The upstream credential mode: per-user or shared, and which credential identifier, never its value.
  7. The outcome, error code and latency, and sizes plus a hash of arguments rather than contents.

INFRO's call record is described as metadata-only by default: time, server, tool, outcome, error code, latency, argument and result sizes, a SHA-256 of the arguments, guardrail counts, and the key, project, environment and attribution; contents are kept only if an owner or admin opts in 8. The calls sit on the same trace as the agent's model calls 7. Separately, the audit log is an append-only record of administrative changes such as keys, connections, policies and membership, kept apart from request traces, and it can be read through the management API with the audit:read scope 9. Use it for "who widened access", and the call record for "who used it".

Never store the access or refresh tokens in these records. If you must correlate a token across systems, store a hash and the jti where the token carries one. Map the checks to your risk register using the OWASP GenAI Security Project, whose Top 10 for LLM applications now lives under the broader project 10.

A checklist before you put a gateway in front of remote MCP servers

  • The gateway publishes RFC 9728 metadata with an exact resource and at least one authorization_servers entry.
  • Unauthenticated requests get a 401 with resource_metadata and a scope hint.
  • Every request is checked for signature, expiry, issuer and an audience equal to the gateway's own resource.
  • No inbound Authorization header is copied upstream, and none is written to logs or caches.
  • Missing scope returns 403 insufficient_scope; step-up retries are bounded.
  • Each upstream server is marked per-user or shared, with the reason written down.
  • Per-user flows keep a per-user registry of approved clients and exact redirect URI matching.
  • The audit record carries principal, client, audience, scopes, tool and credential mode, and no token values.
  • Access tokens are short-lived and refresh tokens rotate for public clients.
  • Offboarding removes a person's grants at the gateway and, for per-user tokens, at the upstream.

Questions readers ask

Does a stdio MCP server need this OAuth flow?
No. The draft specification says implementations using the stdio transport should not follow the HTTP authorization flow and should instead retrieve credentials from the environment 1. The flow in this guide applies to HTTP-based transports, which is what a gateway in front of remote servers speaks.
Is authorization mandatory for a remote MCP server?
The specification calls authorization optional, and says HTTP-based implementations that support it should conform to the spec 1. The MCP tutorial lists needing to audit who performed which actions, and per-user rate limiting, among the reasons to use it 4. A governed gateway usually has both needs.

From the team that builds it

Where this shows up in INFRO

INFRO is a control plane in front of the provider accounts you already hold. The capabilities below are the parts of it this article touches, each with the documentation that defines its behaviour.

  • MCP gateway for your agents' tools

    Available with a plan

    Register your own MCP servers once with their credentials, approve and pin each tool's definition, grant gateway keys access, and let agents call those tools through INFRO with guardrails, a call log on the same trace as their model calls, and kill switches checked on every call. INFRO executes no tool.

    Read the documentation for MCP gateway for your agents' tools
  • Audit log

    Available with a plan

    Member, key, and policy changes recorded with actor and timestamp, viewable in the console.

    Read the documentation for Audit log
  • Request traces and payload logs

    Available with a plan

    Per-request timing detail, with prompt and completion logging off by default and a retention window you choose.

    Read the documentation for Request traces and payload logs

INFRO accounts are self-serve. Provider usage is billed to you by your providers; INFRO charges a software subscription and takes 0% of model spend. See plans.

Sources

Numbered in order of first citation. Each was opened and checked against the claim on the date shown.

  1. 1.Authorization (MCP draft specification) (opens in a new tab) — Model Context Protocol. Accessed Nov 18, 2026.
  2. 2.Authorization Server Discovery (MCP draft specification) (opens in a new tab) — Model Context Protocol. Accessed Nov 18, 2026.
  3. 3.RFC 9728: OAuth 2.0 Protected Resource Metadata (opens in a new tab) — IETF / RFC Editor. Accessed Nov 18, 2026.
  4. 4.Understanding Authorization in MCP (MCP draft) (opens in a new tab) — Model Context Protocol. Accessed Nov 18, 2026.
  5. 5.Authorization Security Considerations (MCP draft specification) (opens in a new tab) — Model Context Protocol. Accessed Nov 18, 2026.
  6. 6.Security Best Practices (MCP draft) (opens in a new tab) — Model Context Protocol. Accessed Nov 18, 2026.
  7. 7.MCP gateway (opens in a new tab) — INFRO Docs. Accessed Nov 18, 2026.
  8. 8.MCP gateway security model (opens in a new tab) — INFRO Docs. Accessed Nov 18, 2026.
  9. 9.Audit log (opens in a new tab) — INFRO Docs. Accessed Nov 18, 2026.
  10. 10.OWASP Top 10 for Large Language Model Applications (opens in a new tab) — OWASP Foundation. Accessed Nov 18, 2026.

About this article

Read the draft MCP authorization specification (overview, authorization server discovery, security considerations), the MCP security best practices and authorization tutorial pages, RFC 9728, the OWASP LLM Top 10 project page and INFRO's MCP gateway and audit log docs on 2026-11-18. The token passthrough section of the best-practices page was only partly retrievable, so only its opening definition is relied on; anything about it beyond that, and any INFRO behaviour not on the pages read, is left out.

Last checked against its sources on . The next review is due by . No separate named reviewer is recorded for this article.

How articles are written, sourced and corrected is set out in the editorial standards.