fix: reuse persisted auth tokens across server restarts - #62
Open
mjdavidson wants to merge 1 commit into
Open
Conversation
Two problems made every restart re-prompt for device authorization: 1. The lifespan cleared the stored tokens in a finally block on every shutdown, destroying the refresh token so it could never be reused. 2. Startup called authenticate() unconditionally, which always begins a new device-authorization flow regardless of any cached token. The silent-refresh path (is_valid_token -> refresh_access_token) only ran on per-tool calls, so it never helped at startup. Remove the shutdown wipe so the access and refresh tokens persist, and have the lifespan reuse them via is_valid_token() — which silently refreshes when the access token is stale — falling back to an interactive device grant only when no valid token can be obtained. clear_tokens() is unchanged and remains the logout primitive. A restart or reconnect now refreshes silently instead of prompting.
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.
The lifespan cleared stored tokens in a
finallyon every shutdown, and startup always ran a fresh device grant — so each restart/reconnect re-prompted for device login and never used the refresh token. This removes the teardown wipe and makes startup reuseis_valid_token()(silent refresh), falling back to a device grant only when no valid token can be obtained.Tests: new
tests/test_lifespan.py(normal exit, exception path, reuse vs. re-auth).