Skip to content

feat: include granted scopes in OAuth refresh token request#731

Merged
DaleSeo merged 2 commits intomainfrom
fix/refresh-token-scopes
Mar 9, 2026
Merged

feat: include granted scopes in OAuth refresh token request#731
DaleSeo merged 2 commits intomainfrom
fix/refresh-token-scopes

Conversation

@DaleSeo
Copy link
Member

@DaleSeo DaleSeo commented Mar 7, 2026

Fixes #624

Motivation and Context

RFC 6749 allows sending a scope parameter with refresh token requests, and some providers, especially Azure AD v2, actually require it. If you don't include it, the refresh might succeed quietly, but it will return a token without any scopes, or the server might reject the request altogether.

This fix keeps the full StoredCredentials, allowing us to add the previously granted scopes to the outgoing refresh request using .add_scope(). This follows the same pattern we already use in the authorization code and client credentials flows. If granted_scopes is empty, we won't send a scope parameter, which maintains the current behavior for providers that don't need it.

auth_request = auth_request.add_scope(Scope::new(scope.to_string()));

request = request.add_scope(Scope::new(scope.clone()));

How Has This Been Tested?

Added unit tests

Breaking Changes

None. Providers that don't accept a scope parameter on refresh requests will continue to work as before, since the parameter is only added when scopes were previously granted.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

@github-actions github-actions bot added T-documentation Documentation improvements T-core Core library changes T-transport Transport layer changes labels Mar 7, 2026
@DaleSeo DaleSeo changed the title Fix/refresh token scopes fix: include granted scopes in OAuth refresh token request Mar 7, 2026
@DaleSeo DaleSeo self-assigned this Mar 7, 2026
@DaleSeo DaleSeo marked this pull request as ready for review March 7, 2026 16:38
@DaleSeo DaleSeo requested a review from a team as a code owner March 7, 2026 16:38
@DaleSeo DaleSeo changed the title fix: include granted scopes in OAuth refresh token request feat: include granted scopes in OAuth refresh token request Mar 7, 2026
);
}

async fn start_token_server() -> (String, Arc<std::sync::Mutex<Option<String>>>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should #[cfg(test)] this yeah?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a private helper inside the #[cfg(test)] mod tests block, so it should be already gated.

@DaleSeo DaleSeo merged commit 54bb522 into main Mar 9, 2026
16 checks passed
@DaleSeo DaleSeo deleted the fix/refresh-token-scopes branch March 9, 2026 20:30
@github-actions github-actions bot mentioned this pull request Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-core Core library changes T-documentation Documentation improvements T-transport Transport layer changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support passing scopes when doing a refresh token flow

2 participants