-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Support upscoping on insufficient_scope 403 #1115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support upscoping on insufficient_scope 403 #1115
Conversation
commit: |
|
@felixweinberger I think this is in-line with SEP-835. Can you take a look? |
|
this duplicates some of #1133 I think we just need to add the 403 handling to the transports (e.g. I don't think we need to change auth.ts) |
pcarleton
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(see prev comment)
I have updated the code to only to handle 403 handling. |
…private Instead of exporting extractFieldFromWwwAuth as a separate function, keep it private and extend extractWWWAuthenticateParams to also return the 'error' field. This provides a cleaner API while maintaining all functionality. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
pcarleton
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! thanks, I tweaked a bit to avoid an extra function export.
This pull request implements support for upscoping when an API request fails with a 403 Forbidden response due to insufficient_scope.
Motivation and Context
Before: When a request failed due to missing scopes, the SDK halted with a hard error, forcing users to manually determine the correct permissions and re-authenticate.
Now: We've introduced graceful error handling for insufficient_scope 403 responses. This change supports upscoping, allowing the SDK to either automatically prompt for the required scopes or guide the user, significantly enhancing resilience and user experience.
What changed (high level)
Extract scope and resource_metadata_url from WWW-Authenticate on 403 responses and use them to trigger an upscoping auth flow via the configured OAuthClientProvider.
Add a guard that records the last WWW-Authenticate header used for an upscoping attempt and prevents retrying an identical directive repeatedly; the guard is reset after successful responses.
Fixes
This resolves the issue described in:
#1039
How Has This Been Tested?
From running npm run test
Test Suites: 40 passed, 40 total
Tests: 836 passed, 836 total
Snapshots: 0 total
Time: 16.599 s
Breaking Changes
No
Types of changes
Checklist
Additional context