fix: validate API tokens in auth status and clear stale tokens on OAuth login#81
Open
thomas-chen-glean wants to merge 3 commits intomainfrom
Open
fix: validate API tokens in auth status and clear stale tokens on OAuth login#81thomas-chen-glean wants to merge 3 commits intomainfrom
thomas-chen-glean wants to merge 3 commits intomainfrom
Conversation
…th login Two auth bugs fixed: 1. `glean auth status` now validates API tokens via a lightweight GET /rest/api/v1/users/me call instead of only checking for a non-empty string. Expired or revoked tokens show a clear error. 2. `glean auth login` (OAuth flow) now clears any existing API token from config/keyring via ClearTokenFromStorage(), preventing stale API tokens from permanently shadowing fresh OAuth credentials (ResolveToken prefers API tokens over OAuth). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…or messages - Switch from GET /users/me (404 on some instances) to POST /search which is universally available. Auth is checked before search executes, so invalid tokens incur no server-side work. - Parse and display the server's error message (e.g. "Token has expired") instead of a generic "token rejected" message. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
glean auth statusnow validates API tokens via a lightweightGET /rest/api/v1/users/mecall instead of only checking for a non-empty string. Expired or revoked tokens display✗ API token is invalid or expiredwith the specific error.glean auth loginclears stale API tokens from config/keyring before persisting OAuth credentials. Previously, a stale API token in~/.glean/config.jsonwould permanently shadow valid OAuth tokens becauseResolveToken()prefers API tokens.ClearTokenFromStorage()to the config package andValidateToken()to the client package.Test plan
TestClearTokenFromStorage— verifies token is cleared while host is preservedTestStaleAPITokenClearedOnOAuthLogin— verifies OAuth login clears stale API tokensTestValidateToken_NoToken/TestValidateToken_Unreachable— verifies validation error pathsglean auth statuswith a valid API token → should show ✓glean auth statuswith an expired/invalid API token → should show ✗glean auth login, verify OAuth token is used afterward🤖 Generated with Claude Code