Skip to content

Stop sending access_token as a refresh_token - #1928

Open
aroh3006 wants to merge 1 commit into
python-social-auth:masterfrom
aroh3006:fix-refresh-token-fallback
Open

Stop sending access_token as a refresh_token#1928
aroh3006 wants to merge 1 commit into
python-social-auth:masterfrom
aroh3006:fix-refresh-token-fallback

Conversation

@aroh3006

@aroh3006 aroh3006 commented Aug 24, 2026

Copy link
Copy Markdown

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.

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

codecov Bot commented Aug 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.36%. Comparing base (d145777) to head (8d9708b).

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     
Flag Coverage Δ
unittests 87.36% <100.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_token fallback when selecting a refresh token in UserMixin.refresh_token().
  • Ensure Zoom and PayPal persist refresh_token in EXTRA_DATA so 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 thread social_core/storage.py
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):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

OAuth2 grant type refresh_token sends the access token when no refresh token is available

2 participants