fix: validate API tokens in auth status and clear stale tokens on OAuth login - #81
Merged
Merged
Conversation
thomas-chen-glean
marked this pull request as draft
April 7, 2026 20:50
thomas-chen-glean
marked this pull request as ready for review
April 8, 2026 21:45
…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>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
steve-calvert-glean
force-pushed
the
thomasychen/auth-fix-1
branch
from
April 10, 2026 17:56
cc1c75b to
81e7d3b
Compare
chris-freeman-glean
approved these changes
Apr 10, 2026
steve-calvert-glean
approved these changes
Apr 10, 2026
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