feat(auth): add persistent OAuth state storage for Claude Desktop account switching #267
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.
Problem
When using this MCP server in Claude Desktop and switching between accounts (e.g., from a Pro account to a Teams account, or Teams to Enterprise), users encounter a critical authentication error:
Root Cause
Claude Desktop restarts the MCP server process when switching between accounts. The OAuth authentication flow works as follows:
This makes it impossible to complete authentication when switching between Claude Desktop accounts.
Solution
This PR implements persistent file-based OAuth state storage that survives process restarts.
Changes
New file:
auth/oauth_state_store.pyPersistentOAuthStateStoreclass~/.google_workspace_mcp/credentials/oauth_states.jsonRLockModified:
auth/oauth21_session_store.py[OAUTH21]and[PERSISTENT STORE]prefixesKey Features
Testing
Tested and verified working:
The persistent state storage successfully validated the state parameter after the restart.
Use Case Impact
This fix is critical for Claude Desktop users who:
Without this fix, users must:
Additional Notes
~/.google_workspace_mcp/credentials/oauth_states.jsonGOOGLE_MCP_CREDENTIALS_DIRenvironment variable