Skip to content

fix(auth): preserve existing refresh_token when OAuth2 refresh omits it - #8481

Open
1828703450qqcom-ux wants to merge 1 commit into
google:mainfrom
1828703450qqcom-ux:fix/oauth2-preserve-refresh-token
Open

1828703450qqcom-ux wants to merge 1 commit into
google:mainfrom
1828703450qqcom-ux:fix/oauth2-preserve-refresh-token

Conversation

@1828703450qqcom-ux

Copy link
Copy Markdown
Contributor

Summary

Preserves the existing refresh_token during OAuth2 token refresh when the authorization server omits refresh_token from its response (per RFC 6749 §6, e.g., Google's oauth2.googleapis.com/token non-rotating refresh grants):

  • src/google/adk/auth/refresher/oauth2_credential_refresher.py:
    • Saves auth_credential.oauth2.refresh_token before calling client.refresh_token(...) and restores it if update_credential_with_tokens(...) cleared refresh_token because the response omitted it.
    • Previously, the first refresh overwrote refresh_token with None (and CredentialManager persisted that corrupted state), causing all subsequent token expirations to abort refresh with "OAuth2 token expired and has no refresh token; cannot refresh".
  • src/google/adk/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.py:
    • Applies the same preservation in OAuth2CredentialExchanger._refresh_token().
  • Regression tests:
    • tests/unittests/auth/refresher/test_oauth2_credential_refresher.py: verifies refresh_token survives consecutive refreshes when omitted by the token endpoint.
    • tests/unittests/tools/openapi_tool/auth/credential_exchangers/test_oauth2_exchanger.py: verifies OAuth2CredentialExchanger.exchange_credential() preserves the existing refresh_token when omitted from a refresh grant response.

Verification

  • .venv\Scripts\python.exe -m pytest tests/unittests/auth/refresher/test_oauth2_credential_refresher.py tests/unittests/tools/openapi_tool/auth/credential_exchangers/test_oauth2_exchanger.py tests/unittests/auth/test_credential_manager.py -q
  • pyink --check, isort --check, ruff check, scripts/compliance_checks.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant