Stop sending access_token as a refresh_token - #1928
Open
aroh3006 wants to merge 1 commit into
Open
Conversation
refresh_token() fell back to access_token when no refresh_token was stored, sending it to the token endpoint as if it were one. Per RFC 6749 4.1.4 a refresh_token is optional and providers reject a request that sends the wrong kind of token, so this always failed with a 401 instead of doing nothing. Removed the fallback. Also added refresh_token to Zoom's and PayPal's EXTRA_DATA, since without it a real refresh_token was never even saved for those two backends. Updated the AzureAD/AzureADB2C test fixtures to include a refresh_token in the mocked login response, matching what those providers actually return. Added tests for the fixed fallback too.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1928 +/- ##
==========================================
+ Coverage 87.32% 87.36% +0.03%
==========================================
Files 352 352
Lines 13713 13740 +27
Branches 675 675
==========================================
+ Hits 11975 12004 +29
+ Misses 1494 1493 -1
+ Partials 244 243 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request fixes an OAuth2 refresh flow bug where refresh_token() incorrectly fell back to sending the access_token as a refresh_token when no refresh token was stored, which providers reject.
Changes:
- Remove the
access_tokenfallback when selecting a refresh token inUserMixin.refresh_token(). - Ensure Zoom and PayPal persist
refresh_tokeninEXTRA_DATAso refresh can actually work. - Update AzureAD/AzureADB2C test fixtures to include
refresh_token, and add regression tests for the corrected refresh-token behavior.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| social_core/storage.py | Stops falling back to access_token when no refresh_token is present. |
| social_core/backends/zoom.py | Adds refresh_token to stored extra data. |
| social_core/backends/paypal.py | Adds refresh_token to stored extra data. |
| social_core/tests/test_storage.py | Adds regression tests ensuring refresh does not use access_token as a refresh token. |
| social_core/tests/backends/test_azuread.py | Updates mocked token response fixture to include refresh_token. |
| social_core/tests/backends/test_azuread_b2c.py | Updates mocked token response fixture to include refresh_token. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+74
to
77
| token = self.extra_data.get("refresh_token") | ||
| backend = self.get_backend_instance(strategy) | ||
| refresh_token = getattr(backend, "refresh_token", None) if backend else None | ||
| if token and callable(refresh_token): |
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.
Fixes #826.
refresh_token() fell back to access_token when no refresh_token was stored, sending it to the token endpoint as if it were one. A refresh_token is optional per RFC 6749 4.1.4, and providers reject a request carrying the wrong kind of token. This always failed with a 401 instead of doing nothing.
Removed the fallback. This also exposed that Zoom and PayPal never actually saved a real refresh_token in the first place, since it wasn't listed in their EXTRA_DATA. Refresh never had a chance to work for those two even with a correct fallback removed. Added it there.
The AzureAD and AzureADB2C tests build their own mocked login response and it didn't include a refresh_token. Their test_refresh_token tests broke once the fallback was gone. Updated those fixtures to match what the providers actually return.
Added tests for the fixed fallback in test_storage.py. Ran the full test suite (1152 passed, 176 skipped, 8 xfailed) and ruff.