Implementation for SEP-2350 Client-side scope accumulation in step-up authorization#1591
Implementation for SEP-2350 Client-side scope accumulation in step-up authorization#1591mikekistler wants to merge 4 commits into
Conversation
…zation Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Implements SEP-2350 step-up authorization behavior in the C# SDK OAuth client flow by accumulating requested scopes across re-authorization attempts, and updates tests/docs to validate and describe the new semantics.
Changes:
- Updated
ClientOAuthProviderto union previously requested scopes with newly challenged scopes (and added locking for thread-safety). - Updated OAuth step-up tests to validate scope accumulation across one and multiple 403
insufficient_scopechallenges. - Added internal documentation updates (PRM metadata semantics) and a new “run conformance from branch” skill guide.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
tests/ModelContextProtocol.AspNetCore.Tests/OAuth/AuthTests.cs |
Expands step-up OAuth tests to validate accumulated scopes across multiple authorization challenges. |
src/ModelContextProtocol.Core/Authentication/ProtectedResourceMetadata.cs |
Updates internal PRM documentation to describe SEP-2350 scope accumulation expectations. |
src/ModelContextProtocol.Core/Authentication/ClientOAuthProvider.cs |
Implements scope accumulation (union) and adds locking around mutable scope state. |
.github/skills/run-conformance-from-branch/SKILL.md |
Adds workflow documentation for running conformance tests against a GitHub branch build. |
| _previouslyRequestedScopes.Add(scope); | ||
| } | ||
|
|
||
| return string.Join(" ", _previouslyRequestedScopes); | ||
| } |
There was a problem hiding this comment.
@copilot are scopes ordered? Is this a correctness concern or just a concern about possible flaky tests that don't treat scopes as unordered?
There was a problem hiding this comment.
OAuth scopes are not ordered — per RFC 6749 §3.3 they're a space-delimited set, so the server treats them as a set regardless of order. This is not a correctness concern for the OAuth protocol.
It is, however, a real flaky test concern: the AuthorizationFlow_UsesScopeFromProtectedResourceMetadata test was asserting an exact scope string ("mcp:tools files:read") that could fail nondeterministically since HashSet enumeration order is not guaranteed.
Fixed in 84b5585 by:
- Sorting scopes with
OrderBy(s => s, StringComparer.Ordinal)before joining inGetScopeParameter, so the emittedscopeparameter is stable and deterministic. - Updating the one test that used an exact string assertion to use an order-independent
HashSetcomparison (consistent with the pattern already used in the other scope tests).
|
|
||
| Return repo to pinned dependency state: | ||
|
|
||
| ```bash |
Agent-Logs-Url: https://github.com/modelcontextprotocol/csharp-sdk/sessions/4331950d-e33b-4bdd-b88a-eb6c8f0f6988 Co-authored-by: mikekistler <85643503+mikekistler@users.noreply.github.com>
Motivation and Context
Implements SEP-2350 client-side scope accumulation for step-up authorization in the C# SDK OAuth client flow.
Fixes: #1547
What changed
Runtime behavior
Thread-safety fix
Documentation/comments
Tests
Updated and added OAuth tests in ModelContextProtocol.AspNetCore.Tests:
All OAuth tests pass across net8.0/net9.0/net10.0 in this branch.
How Has This Been Tested?
Ran auth/scope-step-up against modelcontextprotocol/conformance main (branch install).
Breaking Changes
None.
Types of changes
Checklist
Additional context