bugfix: preserve scope parameter during refresh token requests #2337
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.
Fixes refresh tokens losing their original scopes when
getAccessToken()
triggers a token refresh.🔍 RCA
The
oauth.refreshTokenGrantRequest()
call was missing thescope
parameter inadditionalParameters
, causing Auth0 to return tokens with reduced scopes. Additionally, thescope
property from the OAuth response was not being preserved in the updated token set.📋 Changes
This fix ensures that refresh token requests maintain the same scopes as the original authentication, preventing scope reduction during token refresh operations. The implementation includes proper fallback logic to maintain backward compatibility.
src/server/auth-client.ts
: Added conditionalscope
parameter to refresh token requests and preserved scope in response processingsrc/server/auth-client.test.ts
: Added comprehensive test suite covering scope preservation scenarios including response scope handling, fallback behavior, request parameter validation, and edge cases📎 References
Fixes: #2326
🎯 Testing
Automated:
Added 4 comprehensive test cases covering scope preservation during token refresh:
Manual:
AUTH0_SCOPE
environment variable/api/token-info
getAccessToken()
/api/token-info