Skip to content

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
thomasychen/auth-fix-1
Open

fix: validate API tokens in auth status and clear stale tokens on OAuth login#81
thomas-chen-glean wants to merge 3 commits intomainfrom
thomasychen/auth-fix-1

Conversation

@thomas-chen-glean
Copy link
Copy Markdown

Summary

  • 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 display ✗ API token is invalid or expired with the specific error.
  • glean auth login clears stale API tokens from config/keyring before persisting OAuth credentials. Previously, a stale API token in ~/.glean/config.json would permanently shadow valid OAuth tokens because ResolveToken() prefers API tokens.
  • Adds ClearTokenFromStorage() to the config package and ValidateToken() to the client package.

Test plan

  • TestClearTokenFromStorage — verifies token is cleared while host is preserved
  • TestStaleAPITokenClearedOnOAuthLogin — verifies OAuth login clears stale API tokens
  • TestValidateToken_NoToken / TestValidateToken_Unreachable — verifies validation error paths
  • Manual: run glean auth status with a valid API token → should show ✓
  • Manual: run glean auth status with an expired/invalid API token → should show ✗
  • Manual: set a stale API token, run glean auth login, verify OAuth token is used afterward

🤖 Generated with Claude Code

…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>
@thomas-chen-glean thomas-chen-glean marked this pull request as draft April 7, 2026 20:50
thomas-chen-glean and others added 2 commits April 7, 2026 16:11
…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>
@thomas-chen-glean thomas-chen-glean marked this pull request as ready for review April 8, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants