OAuthClientProvider replaces a scope explicitly configured by the client with all scopes discovered from the protected resource or authorization server. This can request broader permissions than the application intended and can fail against servers that advertise scopes the client is not allowed to request.
Root Cause
The OAuth flow unconditionally assigned the result of get_client_metadata_scopes(...) to client_metadata.scope, so the configured value was not treated as authoritative.
Solution
Keep an explicitly configured scope, including an explicit empty string, while still applying the existing offline_access augmentation for non-empty configured scopes when the AS supports refresh-token grants.
Changes
Add an optional configured-scope input to the shared scope-selection helper.
Preserve configured scope during OAuth discovery.
Add an end-to-end regression test covering discovered scopes that differ from the client-selected scope.
The helper's existing discovery behavior remains the default. Explicit non-empty scopes still receive the existing offline_access addition when applicable; explicit empty scope remains empty. No public constructor or field is renamed.
Notes for Reviewer
Pyright is unverified locally because the incremental worktree does not contain the repository .venv; the available alternate environment has mismatched project dependencies and produces unrelated baseline import/type diagnostics.
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
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.
Problem
OAuthClientProvider replaces a scope explicitly configured by the client with all scopes discovered from the protected resource or authorization server. This can request broader permissions than the application intended and can fail against servers that advertise scopes the client is not allowed to request.
Root Cause
The OAuth flow unconditionally assigned the result of get_client_metadata_scopes(...) to client_metadata.scope, so the configured value was not treated as authoritative.
Solution
Keep an explicitly configured scope, including an explicit empty string, while still applying the existing offline_access augmentation for non-empty configured scopes when the AS supports refresh-token grants.
Changes
Testing
Compatibility/Risk
The helper's existing discovery behavior remains the default. Explicit non-empty scopes still receive the existing offline_access addition when applicable; explicit empty scope remains empty. No public constructor or field is renamed.
Notes for Reviewer
Pyright is unverified locally because the incremental worktree does not contain the repository .venv; the available alternate environment has mismatched project dependencies and produces unrelated baseline import/type diagnostics.
Linked Issue
Closes #2317