Fix: fall back to full auth flow when refresh token is invalid#95
Open
jmneto wants to merge 1 commit intotylerebowers:mainfrom
Open
Fix: fall back to full auth flow when refresh token is invalid#95jmneto wants to merge 1 commit intotylerebowers:mainfrom
jmneto wants to merge 1 commit intotylerebowers:mainfrom
Conversation
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.
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.