fix(auth): prevent OAuth stdout corruption and handle expired tokens#115
Open
timothedelion wants to merge 1 commit intomainfrom
Open
fix(auth): prevent OAuth stdout corruption and handle expired tokens#115timothedelion wants to merge 1 commit intomainfrom
timothedelion wants to merge 1 commit intomainfrom
Conversation
…nd handle expired tokens gracefully OAuth print() calls wrote banners to stdout, which is the MCP JSON-RPC channel in stdio mode. This corrupted the protocol and caused Claude Code to report "Failed to connect". Additionally, expired stored tokens triggered a blocking 5-minute interactive OAuth flow during server startup instead of letting the API validate and the 401 handler re-authenticate automatically. Changes: - Replace all print() with logger.info() in oauth.py to keep stdout clean - Return expired tokens from FileTokenStorage instead of None, deferring validation to the API and leveraging the existing 401 refresh handler - Add 30s timeout on scope fetching during lifespan to prevent indefinite blocking if re-authentication is triggered at startup
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.
Summary
print()withlogger.info()in OAuth flow —print()writes to stdout, which is the MCP JSON-RPC channel in stdio mode. This corrupted the protocol and caused Claude Code CLI to report✗ Failed to connecton health check, with all tool calls silently rejected.FileTokenStorageinstead ofNone— Previously, an expired stored token causedacquire_single_tenant_token()to fall through to the interactive OAuth flow, blocking server startup for up to 5 minutes. Now the expired token is returned and the API validates it; the existing 401 →_refresh_token()path handles re-authentication automatically.get_authenticated_user_info,revoke_current_token) remain available since they have norequired_scopes.Test plan
~/Library/Application Support/GitGuardian/mcp_oauth_tokens.json, verify the server starts and connects to Claude Code (noFailed to connect)