Skip to content

feat(auth): add logout/clear commands and stale-token detection - #15

Open
robpc wants to merge 2 commits into
mainfrom
feat/auth-logout-clear-and-stale-detection
Open

robpc wants to merge 2 commits into
mainfrom
feat/auth-logout-clear-and-stale-detection

Conversation

@robpc

@robpc robpc commented May 5, 2026

Copy link
Copy Markdown
Owner

Cherry-picked from yahoo-orion/desk#52 (now archived) by Jess Finger.

Why this is here

The yahoo-orion/desk repo was archived as part of the OSS migration to robpc/desk. Jess's #52 was open at the time of archive and is genuinely novel work — robpc/desk doesn't have an equivalent today (no desk auth logout / desk auth clear commands, no stale-token detection, ADR-017 in this repo is "Paragraph Spacing", not auth-logout-clear).

Bringing the work over here with attribution preserved. Tagging Jess for review/take-over if she wants.

Changes

New commands

When desk's keychain state goes stale (e.g. the stored OAuth token was minted against a different OAuth client than the one currently configured, or scopes drift after a SCOPES change), the only way to recover today is manual keychain surgery via the security CLI. The underlying keyring helpers exist in keyring_store.py but aren't exposed via the CLI, and auth status doesn't surface enough to even diagnose the mismatch.

This adds:

  • desk auth logout — clears the OAuth token only (keeps the configured client)
  • desk auth clear — clears both the token and the client config (full reset)
  • Stale-token detection in auth status — surfaces client/token mismatch and scope drift

Files

  • docs/decisions/019-auth-logout-clear-and-stale-token-detection.md — ADR for the design (renumbered from 017 in the source PR to avoid colliding with this repo's ADR-017 Paragraph Spacing)
  • src/desk/auth.py, src/desk/cli.py, src/desk/keyring_store.py — implementation
  • tests/test_auth_logout_clear.py — new test suite

Commits

  1. bebb0b5 — original commit by Jess Finger (cherry-picked with -x from yahoo-orion/desk@e7302a8)
  2. 166f3c8 — small follow-up: renumber the ADR file and heading from 017 to 019 to avoid collision

Notes

  • Original PR body, comments, and review threads are at yahoo-orion/desk#52 — preserved in archive.
  • Authorship trailer on the cherry-pick preserves Jess's identity. CC @jfinger or whoever should drive review.

🤖 Generated with Claude Code

Jess Finger and others added 2 commits May 5, 2026 12:26
Today, recovering from stale keychain state (e.g. token issued for a
different OAuth client than the one currently configured) requires manual
keychain surgery via the `security` CLI. The underlying keyring helpers
exist but are not exposed via the CLI.

Adds:

- `desk auth logout` — removes the OAuth token from the keychain
  (preserves client config); idempotent; scrubs legacy ~/.desk/token.json
  secrets; --json supported.
- `desk auth clear` — removes token and/or client credentials with
  --token / --client flags; confirmation prompt by default; --yes to
  skip; non-interactive mode requires --yes (matches `docs delete-tab`);
  --json supported.
- `desk auth status` — surfaces client_id, token_client_id, token_source
  (keyring/file/gcloud_adc/none), and scopes so users can spot stale
  state.
- `desk auth set-client` — when the new client_id differs from the
  stored token's client_id, automatically invalidate the token (it
  cannot refresh against a different client) and print a one-line note.

Also adds keyring_store.delete_client_credentials() to mirror
delete_token().

Documented in ADR-017.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
(cherry picked from commit e7302a88bf9cbb158a38e49dcb26246e1bdc1493)
The cherry-picked auth-logout-clear ADR was numbered 017 in the source
repo (yahoo-orion/desk), but robpc/desk already has ADR-017 (Paragraph
Spacing Controls) referenced from ideas/047 and ideas/048. Renumbering
to 019 (018 is taken by tab-identifier-resolution).

No content changes — just the file name and the heading.
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.

1 participant