Skip to content

feat(auth): use OAuth refresh tokens for CLI sessions - #24

Merged
fatflowers merged 3 commits into
mainfrom
codex/oauth-refresh-tokens
Sep 10, 2026
Merged

fatflowers merged 3 commits into
mainfrom
codex/oauth-refresh-tokens

Conversation

@fatflowers

@fatflowers fatflowers commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Browser login currently exchanges Clerk access tokens for permanent API keys. This change stores OAuth access/refresh tokens and the registered client ID directly, refreshes near expiry, and retries an authenticated API or Router request once after a 401.

  • Store credentials atomically with mode 0600; retain static-key env/--key support, migrate ~/.aisa/key, and keep write-only compatibility mirrors.
  • Serialize refresh, logout, and login replacement across processes with a heartbeat file lock. Logout and replacement revoke the previous refresh token before removing/replacing credentials.
  • Preserve newly issued grants in private recovery files if lock acquisition or cleanup fails, so subsequent login/logout can revoke them. Persist rotated credentials before optional metadata/mirrors; report primary persistence failures explicitly.
  • Handle asynchronous credential failures consistently in logout, whoami, and MCP setup. Reject OAuth responses without a usable refresh token before replacing the existing session.
  • Update async callers, authentication copy, documentation, and package/E2E checks.

Validation: TypeScript check and build; 350 Vitest tests, including six independent-process tests and injected persistence/lock failures; isolated package smoke. Earlier live Clerk verification covered browser login, refresh-token rotation, balance access, and logout followed by HTTP 400 invalid_grant for the revoked refresh token. Final recovery changes use isolated fault-injection tests, not production credentials.

Limits: already-issued JWT access tokens remain valid until expiry. Third-party client configurations still receive a fixed access-token snapshot; automatic refresh for those clients is outside this change.

Comment thread src/commands/auth.ts
Comment thread src/commands/oauth-login.ts
@fatflowers
fatflowers merged commit b6c017b into main Sep 10, 2026
5 checks passed
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