Skip to content

Fix: fall back to full auth flow when refresh token is invalid#95

Open
jmneto wants to merge 1 commit intotylerebowers:mainfrom
jmneto:pr/tokenreauth
Open

Fix: fall back to full auth flow when refresh token is invalid#95
jmneto wants to merge 1 commit intotylerebowers:mainfrom
jmneto:pr/tokenreauth

Conversation

@jmneto
Copy link

@jmneto jmneto commented Mar 10, 2026

When _update_access_token() fails because the refresh token is expired or invalid, the current code logs an error and stops — leaving the user with no working tokens and no way to recover without manual intervention.

This change adds a fallback: if the access token refresh request fails (HTTP error from Schwab's OAuth endpoint), the code automatically triggers _update_refresh_token() to start the full re-authorization flow, allowing the user to re-authenticate and obtain fresh tokens.

What changed in schwabdev/tokens.py:

In _update_access_token(): when the refresh token POST returns an error response, instead of silently returning, it now logs a warning and calls _update_refresh_token() to initiate the full OAuth authorization code flow.
Why:

Refresh tokens expire after 7 days. If an application is idle beyond that window, the access token refresh silently fails with no recovery path — the user must manually restart or re-authenticate. This fix makes token recovery automatic.

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