Skip to content

fix: validate API tokens in auth status and clear stale tokens on OAuth login - #81

Merged
steve-calvert-glean merged 4 commits into
mainfrom
thomasychen/auth-fix-1
Apr 10, 2026
Merged

fix: validate API tokens in auth status and clear stale tokens on OAuth login#81
steve-calvert-glean merged 4 commits into
mainfrom
thomasychen/auth-fix-1

Conversation

@thomas-chen-glean

Copy link
Copy Markdown
Contributor

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

@thomas-chen-glean
thomas-chen-glean marked this pull request as draft April 7, 2026 20:50
Comment thread internal/auth/auth.go Outdated
Comment thread internal/config/config_test.go Outdated
Comment thread internal/auth/auth.go Outdated
@thomas-chen-glean
thomas-chen-glean marked this pull request as ready for review April 8, 2026 21:45
thomas-chen-glean and others added 4 commits April 10, 2026 10:49
…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
steve-calvert-glean requested a review from a team as a code owner April 10, 2026 17:56
@steve-calvert-glean steve-calvert-glean added the bug Something isn't working label Apr 10, 2026
@steve-calvert-glean
steve-calvert-glean merged commit 5054f3b into main Apr 10, 2026
7 checks passed
@steve-calvert-glean
steve-calvert-glean deleted the thomasychen/auth-fix-1 branch April 10, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants