Skip to content

Commit e651f3c

Browse files
committed
Cover the auth families: the RFC 9207 iss table, step-up bounds, DCR and refresh
The full iss validation table from the 2026 authorization-response rules: match accepted, trailing-slash difference rejected without normalization (both comparison strings pinned as harness literals so server-side issuer serialization changes cannot invert the test), missing-iss rejected when advertised and tolerated when not, an unadvertised-but-present iss still validated, and an error redirect with a mismatched iss rejected on iss before the missing-code error - the ordering that proves validation applies equally to error responses. Step-up bounds: a second insufficient-scope 403 after one step-up surfaces as an error without another authorize round trip, and a 403 on the GET stream open steps up and reopens with the upgraded token (era-bound: the GET stream is removed at 2026-07-28). DCR defaults (grant_types omitted and passed through verbatim), refresh-token rotation handling at the single-refresh seam (replacement stored, preservation honoured when the server does not rotate), and a non-2xx token response surfacing typed. The as-binding entry splits into its two spec obligations (re-register and no-credential-reuse), both decorating the existing test unchanged. Harness: three small review-approved knobs (iss visibility, code override, persistent step-up shim, non-rotating provider). 16 entries minted (13 tested, 3 deferred), 931 -> 944 cells exact; suite green three runs.
1 parent 48d76c3 commit e651f3c

6 files changed

Lines changed: 851 additions & 17 deletions

File tree

‎tests/interaction/_requirements.py‎

Lines changed: 248 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5334,6 +5334,57 @@ def __post_init__(self) -> None:
53345334
transports=("streamable-http",),
53355335
note="OAuth is HTTP-only.",
53365336
),
5337+
"client-auth:stepup:retry-cap": Requirement(
5338+
source=f"{SPEC_BASE_URL}/basic/authorization#step-up-authorization-flow",
5339+
behavior=(
5340+
"Step-up re-authorization is bounded per request send: one re-authorization and one "
5341+
"retry, after which a further insufficient_scope 403 on the retried request "
5342+
"surfaces to the caller as an error without another authorization attempt."
5343+
),
5344+
transports=("streamable-http",),
5345+
note=(
5346+
"OAuth is HTTP-only. The bound is structural -- the auth flow performs at most one "
5347+
"step-up before its generator ends -- not a configurable retry count; the surfaced "
5348+
"error is the transport's INTERNAL_ERROR stand-in for a non-2xx final response. "
5349+
"Cross-request attempt tracking is the separate deferred "
5350+
"client-auth:stepup:attempt-tracking."
5351+
),
5352+
),
5353+
"client-auth:stepup:get-stream-403": Requirement(
5354+
source=f"{SPEC_BASE_URL}/basic/authorization#step-up-authorization-flow",
5355+
behavior=(
5356+
"A 403 insufficient_scope challenge on the standalone GET stream open receives the "
5357+
"same step-up handling as the POST path: the scope union is re-authorized once and "
5358+
"the stream is established on the retried GET with the upgraded token."
5359+
),
5360+
transports=("streamable-http",),
5361+
removed_in="2026-07-28",
5362+
note=(
5363+
"OAuth is HTTP-only. The standalone GET stream is a 2025-11-25 transport mechanism "
5364+
"removed at 2026-07-28; the auth suite's legacy-mode connect is its natural home. "
5365+
"The uniformity is structural (the OAuth provider wraps every request the transport "
5366+
"issues), but the GET leg's choreography is pinned because a failed step-up there "
5367+
"would otherwise vanish into the stream's silent reconnect loop."
5368+
),
5369+
),
5370+
"client-auth:stepup:attempt-tracking": Requirement(
5371+
source=f"{SPEC_BASE_URL}/basic/authorization#step-up-authorization-flow",
5372+
behavior=(
5373+
"The client tracks scope-upgrade attempts across request sends to avoid repeated "
5374+
"failures for the same resource and operation combination."
5375+
),
5376+
transports=("streamable-http",),
5377+
note="OAuth is HTTP-only. The per-send bound is client-auth:stepup:retry-cap.",
5378+
deferred=(
5379+
"Not implemented in the SDK: the client OAuth provider keeps no cross-request memory "
5380+
"of scope-upgrade attempts. The 403 insufficient_scope branch "
5381+
"(src/mcp/client/auth/oauth2.py:704-734) performs one inline step-up per send with no "
5382+
"attempt counter and no (resource, operation) key, and OAuthContext (oauth2.py:98) "
5383+
"carries no field recording prior step-up failures, so a second send for the same "
5384+
"resource and operation re-attempts the upgrade unconditionally. The per-send "
5385+
'"repeated 403s do not loop" half of this spec line is client-auth:403-scope-upgrade.'
5386+
),
5387+
),
53375388
"client-auth:as-metadata-discovery:priority-order": Requirement(
53385389
source=f"{SPEC_BASE_URL}/basic/authorization#authorization-server-metadata-discovery",
53395390
behavior=(
@@ -5420,12 +5471,68 @@ def __post_init__(self) -> None:
54205471
transports=("streamable-http",),
54215472
note="OAuth is HTTP-only.",
54225473
),
5423-
"client-auth:as-binding": Requirement(
5474+
"client-auth:dcr:app-type-heuristic": Requirement(
5475+
source=(
5476+
f"{SPEC_2026_BASE_URL}"
5477+
"/basic/authorization/client-registration#application-type-and-redirect-uri-constraints"
5478+
),
5479+
behavior=(
5480+
"When the client metadata does not set application_type, dynamic client "
5481+
"registration derives it from the redirect URIs: a loopback host or custom URI "
5482+
"scheme yields 'native', otherwise 'web' (SEP-837)."
5483+
),
5484+
added_in="2026-07-28",
5485+
transports=("streamable-http",),
5486+
note=(
5487+
"OAuth is HTTP-only. The spec MUST (always send an application_type) IS satisfied "
5488+
"at this pin: OAuthClientMetadata defaults the field to 'native' and every "
5489+
"registration body carries it, pinned incidentally by the "
5490+
"client-auth:dcr:grant-types-default body snapshot. Only the derive-from-redirect-"
5491+
"URIs strategy for the 'web' SHOULD is unimplemented; a web-app consumer sets "
5492+
"application_type='web' explicitly and it is transmitted verbatim."
5493+
),
5494+
deferred=(
5495+
"Not implemented in the SDK: application_type is a static model default ('native') "
5496+
"on OAuthClientMetadata (src/mcp/shared/auth.py); no code path inspects the "
5497+
"redirect URIs to choose between 'native' and 'web'."
5498+
),
5499+
),
5500+
"client-auth:dcr:grant-types-default": Requirement(
5501+
source=f"{SPEC_2026_BASE_URL}/basic/authorization#refresh-tokens",
5502+
behavior=(
5503+
"When the client metadata does not set grant_types, the dynamic-registration "
5504+
"request carries ['authorization_code', 'refresh_token'] so the authorization "
5505+
"server may issue refresh tokens (SEP-2207); a consumer-set grant_types is sent "
5506+
"verbatim, never rewritten."
5507+
),
5508+
added_in="2026-07-28",
5509+
transports=("streamable-http",),
5510+
note=(
5511+
"OAuth is HTTP-only. A SHOULD. Python implements the default on the "
5512+
"OAuthClientMetadata model (a field default), not in registration code, so it is "
5513+
"present from construction -- wire-observably identical to injecting it at "
5514+
"registration time, which is what the registration body pins."
5515+
),
5516+
),
5517+
"client-auth:as-binding:reregister": Requirement(
5518+
source=f"{SPEC_2026_BASE_URL}/basic/authorization/client-registration#authorization-server-binding",
5519+
behavior=(
5520+
"Stored client credentials are bound to the issuer that registered them; when the "
5521+
"authorization server changes, the client discards them and re-registers with the "
5522+
"new authorization server (SEP-2352)."
5523+
),
5524+
added_in="2026-07-28",
5525+
transports=("streamable-http",),
5526+
note="OAuth is HTTP-only.",
5527+
),
5528+
"client-auth:as-binding:no-cred-reuse": Requirement(
54245529
source=f"{SPEC_2026_BASE_URL}/basic/authorization/client-registration#authorization-server-binding",
54255530
behavior=(
5426-
"Stored client credentials are bound to the issuer that registered them; when the authorization "
5427-
"server changes, the client discards them and re-registers rather than reusing them (SEP-2352)."
5531+
"When the authorization server changes, the client never reuses credentials from "
5532+
"the previous authorization server: the stale client_id reaches neither the "
5533+
"authorize nor the token endpoint (SEP-2352)."
54285534
),
5535+
added_in="2026-07-28",
54295536
transports=("streamable-http",),
54305537
note="OAuth is HTTP-only.",
54315538
),
@@ -5520,6 +5627,29 @@ def __post_init__(self) -> None:
55205627
transports=("streamable-http",),
55215628
note="OAuth is HTTP-only.",
55225629
),
5630+
"client-auth:refresh:rotation-handling": Requirement(
5631+
source=f"{SPEC_2026_BASE_URL}/basic/authorization#refresh-tokens",
5632+
behavior=(
5633+
"On a refresh-token exchange, a new refresh_token in the response replaces the "
5634+
"stored one, and a response that omits refresh_token leaves the stored one in "
5635+
"place -- the client never assumes a refresh token will be issued "
5636+
"(RFC 6749 section 6 / SEP-2207)."
5637+
),
5638+
transports=("streamable-http",),
5639+
note=(
5640+
"OAuth is HTTP-only. No added_in: the replace/preserve mechanics are RFC 6749 "
5641+
"section 6 client behaviour that predates the 2026 Refresh Tokens section restating "
5642+
"them (the add plan classifies this entry era PRE-EXISTING), and the auth tests "
5643+
"bypass the connect fixture so era fields drive no cells. The follow-on claim -- "
5644+
"the NEXT refresh presents the rotated token -- is real-time-bound at this pin: a "
5645+
"token that is already expired when its refresh response arrives is not refreshed "
5646+
"again on the same request; the request goes out unauthenticated and 401s into a "
5647+
"full re-authorization (oauth2.py sends at most one refresh per request and only "
5648+
"attaches a bearer it considers valid), so a second same-connection refresh cannot "
5649+
"be driven without wall-clock waits. The tests therefore pin replacement and "
5650+
"preservation at the storage/wire seam of a single refresh."
5651+
),
5652+
),
55235653
"client-auth:refresh:transparent": Requirement(
55245654
source="sdk",
55255655
behavior=(
@@ -5574,12 +5704,127 @@ def __post_init__(self) -> None:
55745704
transports=("streamable-http",),
55755705
note="OAuth is HTTP-only.",
55765706
),
5707+
"client-auth:iss:match": Requirement(
5708+
source=f"{SPEC_2026_BASE_URL}/basic/authorization#authorization-response-validation",
5709+
behavior=(
5710+
"When the authorization server's metadata advertises "
5711+
"authorization_response_iss_parameter_supported and the callback's iss equals the "
5712+
"recorded metadata issuer, the client proceeds to redeem the authorization code "
5713+
"(RFC 9207 validation table row 1)."
5714+
),
5715+
added_in="2026-07-28",
5716+
transports=("streamable-http",),
5717+
note="OAuth is HTTP-only.",
5718+
),
5719+
"client-auth:iss:no-normalize": Requirement(
5720+
source=f"{SPEC_2026_BASE_URL}/basic/authorization#authorization-response-validation",
5721+
behavior=(
5722+
"The iss comparison is simple string comparison (RFC 3986 section 6.2.1): a value "
5723+
"differing from the recorded issuer only by a trailing slash is rejected as a "
5724+
"mismatch -- no scheme or host case folding, default-port elision, trailing-slash, "
5725+
"or percent-encoding normalization is applied before comparison."
5726+
),
5727+
added_in="2026-07-28",
5728+
transports=("streamable-http",),
5729+
note=(
5730+
"OAuth is HTTP-only. The comparison is a single string inequality; the test pins the "
5731+
"trailing-slash arm as the representative normalization class."
5732+
),
5733+
),
5734+
"client-auth:iss:supported-missing-reject": Requirement(
5735+
source=f"{SPEC_2026_BASE_URL}/basic/authorization#authorization-response-validation",
5736+
behavior=(
5737+
"When the authorization server's metadata advertises "
5738+
"authorization_response_iss_parameter_supported: true and the callback carries no "
5739+
"iss, the client rejects the authorization response before redeeming the code "
5740+
"(RFC 9207 validation table row 2)."
5741+
),
5742+
added_in="2026-07-28",
5743+
transports=("streamable-http",),
5744+
note="OAuth is HTTP-only.",
5745+
),
5746+
"client-auth:iss:unadvertised-proceed": Requirement(
5747+
source=f"{SPEC_2026_BASE_URL}/basic/authorization#authorization-response-validation",
5748+
behavior=(
5749+
"When the authorization server's metadata does not advertise "
5750+
"authorization_response_iss_parameter_supported and the callback carries no iss, "
5751+
"the client proceeds with the code exchange (RFC 9207 validation table row 4)."
5752+
),
5753+
added_in="2026-07-28",
5754+
transports=("streamable-http",),
5755+
note="OAuth is HTTP-only.",
5756+
),
5757+
"client-auth:iss:unadvertised-present-validated": Requirement(
5758+
source=f"{SPEC_2026_BASE_URL}/basic/authorization#authorization-response-validation",
5759+
behavior=(
5760+
"A present iss is validated against the recorded issuer regardless of metadata "
5761+
"advertisement (RFC 9207 validation table row 3, where this specification "
5762+
"deliberately exceeds RFC 9207's local-policy provision): a matching iss proceeds "
5763+
"and a mismatching iss is rejected."
5764+
),
5765+
added_in="2026-07-28",
5766+
transports=("streamable-http",),
5767+
note=(
5768+
"OAuth is HTTP-only. Covered by two tests: the match half directly, and the "
5769+
"mismatch half by the client-auth:iss:mismatch-reject test, which drives a "
5770+
"mismatched iss against the suite's unadvertising authorization server."
5771+
),
5772+
),
5773+
"client-auth:iss:error-response-validated": Requirement(
5774+
source=f"{SPEC_2026_BASE_URL}/basic/authorization#authorization-response-validation",
5775+
behavior=(
5776+
"iss validation applies equally to error responses: a mismatched iss on an error "
5777+
"callback is rejected before the flow acts on the response, and on mismatch the "
5778+
"client must not act on or display error, error_description, or error_uri."
5779+
),
5780+
added_in="2026-07-28",
5781+
transports=("streamable-http",),
5782+
note=(
5783+
"OAuth is HTTP-only. The non-surfacing half holds by construction: the callback "
5784+
"contract (AuthorizationCodeResult) carries no error fields, so those values never "
5785+
"enter the SDK; the test pins the observable half -- the iss mismatch is raised in "
5786+
"preference to the missing-authorization-code failure."
5787+
),
5788+
),
55775789
"client-auth:token-endpoint-auth-method": Requirement(
55785790
source="sdk",
55795791
behavior="The client authenticates to the token endpoint using the auth method established at registration.",
55805792
transports=("streamable-http",),
55815793
note="OAuth is HTTP-only.",
55825794
),
5795+
"client-auth:token-error:machine-readable-code": Requirement(
5796+
source="sdk",
5797+
behavior=(
5798+
"An RFC 6749 error response from the token endpoint (e.g. invalid_grant, "
5799+
"invalid_client, on either the authorization-code exchange or a refresh) surfaces "
5800+
"to the caller as a typed OAuth error carrying the wire error code as a "
5801+
"machine-readable field, not only embedded in the message text."
5802+
),
5803+
transports=("streamable-http",),
5804+
note="OAuth is HTTP-only. The weak testable sibling is client-auth:token:error-surfaces.",
5805+
deferred=(
5806+
"Not implemented in the SDK: OAuthTokenError (src/mcp/client/auth/exceptions.py) "
5807+
"carries only a message string; the token-response handler embeds the RFC 6749 "
5808+
"error body in an f-string and the refresh-response handler clears tokens without "
5809+
"reading the body (src/mcp/client/auth/oauth2.py), so there is no machine-readable "
5810+
"error code for a caller to branch on."
5811+
),
5812+
),
5813+
"client-auth:token:error-surfaces": Requirement(
5814+
source="sdk",
5815+
behavior=(
5816+
"A non-2xx response from the token endpoint on the authorization-code exchange "
5817+
"aborts the flow and surfaces to the caller as an error naming the HTTP status; "
5818+
"the flow does not loop, and no request is ever sent with a bearer token."
5819+
),
5820+
transports=("streamable-http",),
5821+
note=(
5822+
"OAuth is HTTP-only. Completes the endpoint error-surfaces family alongside "
5823+
"client-auth:authorize:error-surfaces and "
5824+
"client-auth:dcr:registration-rejected-error; the machine-readable half is "
5825+
"client-auth:token-error:machine-readable-code (deferred)."
5826+
),
5827+
),
55835828
"client-auth:token-provenance": Requirement(
55845829
source=f"{SPEC_BASE_URL}/basic/authorization#token-handling",
55855830
behavior=(

0 commit comments

Comments
 (0)