Repository navigation
fix(oauth): request the scope named by the server's 401 Bearer challenge - #2399
Open
Adityakk9031 wants to merge 2 commits into
Open
Adityakk9031 wants to merge 2 commits into
Adityakk9031 wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WWW-Authenticate: Bearer …challenge (scopeattribute, RFC 6750 §3) when connecting. The challenge's scope takes precedence over the protected resource metadata'sscopes_supported; the metadata list remains the fallback when the challenge names no scope, and the authorization-server metadata fallback is unchanged.Fixes #2304.
Servers built on better-auth's MCP plugin answer a request to the resource with
WWW-Authenticate: Bearer resource_metadata="…", scope="mcp offline_access"while theirprotected resource metadata correctly lists only
mcp(RFC 9728 —offline_accessis not ascope on the resource). Executor previously took scopes only from the metadata, so it
authorized with
scope=mcp, got no refresh token, and the connection showed Expired assoon as the first access token lapsed.
Verification
discoverProtectedResourceMetadatasurfaces the challenge'sscopeattribute aschallengeScopealongside the metadata it names (including when the challenge omitsresource_metadata): new cases inpackages/core/sdk/src/oauth-discovery.test.ts.oauth.startend-to-end on a better-auth-shaped fixture: the authorize URL requestsmcp offline_accesswhen the challenge carriesscope, and still requests exactly theresource's
scopes_supported(mcp) when the challenge names no scope: cases(m)/(n)in
packages/core/sdk/src/oauth-scope-union.test.ts.packages/core/sdksuite green (64 files, 964 tests) andpackages/core/apigreen(10 files, 134 tests);
oxlintclean on the touched files;tsgo --noEmitexits 0 withonly pre-existing diagnostics.