7.6 KiB
Credential System v2 (API + OAuth/token) — Implementation Checklist
Archived (2026-02-18): Historical implementation checklist. Canonical status is tracked in
docs/plans/state.json; unchecked boxes here are not active backlog unless explicitly re-opened.
Date: 2026-02-15
Parent roadmap: docs/plans/2026-02-15-openclaw-gap-roadmap.md
Goal: Close the gap item "OAuth subscription auth" by supporting both API-key credentials and OAuth/token-based credentials (provider-specific) with consistent UX, per-tier control, and deterministic resolution.
Scope Summary
- Add
auth_modeper tier (default/fast/complex/local and anylocal_providersentries). - Keep backward compatibility with existing
use_oauthbehavior. - Add stored credential support where it currently doesn't exist:
- OpenAI: stored API key (OAuth already exists)
- Anthropic: stored auth token (API key already exists)
- Improve doctor output to surface which auth sources are present (without revealing secrets).
Non-goals (explicitly out of scope for this checklist):
- Inventing an Anthropic OAuth device flow.
- Building new provider integrations (Vercel/MiniMax/etc.).
Current Baseline (important constraints)
- OpenAI OAuth uses the ChatGPT/Codex backend endpoint (SSE) and currently does not support tools on that path.
- Source:
src/models/openai.ts
- Source:
- Anthropic supports
apiKeyandauthTokeninAnthropicClientConfig.- Source:
src/models/anthropic.ts
- Source:
- Stored credentials live at
~/.config/flynn/auth.json.- Source:
src/auth/openai.ts,src/auth/anthropic.ts
- Source:
Design Decisions
1) New config field: auth_mode
Add auth_mode to the per-tier model config:
auto(default)api_keyoauth
oauth is interpreted as "OAuth/token mode" (provider-specific). For Anthropic, that means auth_token.
2) Backward compatibility: use_oauth
Preserve use_oauth as a compatibility alias.
Recommended rule:
- If
auth_modeis set: it wins. - Else if
use_oauth: true: treat asauth_mode: oauth.
3) Credential resolution order
For each provider, resolve the required credential type by trying:
- config (
api_key/auth_token) - env var
- auth store (
~/.config/flynn/auth.json)
auth_mode controls which credential type is required.
PR Breakdown (atomic, test-backed)
PR 1 — Schema + docs: per-tier auth_mode
Checklist:
- Add
auth_modetomodelConfigBaseSchemainsrc/config/schema.ts. - Update
src/config/schema.test.tsto cover defaults + validation. - Update
README.mdconfig examples (brief mention). - Update
config/default.yamlcomment/help text (brief mention).
Acceptance:
- Config parses with no changes (defaults preserved).
- Setting
auth_mode: oauthorauth_mode: api_keyvalidates.
Tests:
pnpm test:run src/config/schema.test.ts
PR 2 — OpenAI auth store: add API-key storage
Goal: allow OpenAI to run without api_key in YAML.
Checklist:
- Extend
src/auth/openai.tsAuthStoreshape to allowopenai.api_keyalongside existing OAuth info. - Add functions:
loadStoredOpenAIApiKey()storeOpenAIApiKey(key)clearOpenAIApiKey()getOpenAIApiKey()(env override + store)
- Keep existing OAuth store code working unchanged.
- Add/extend tests for new store functions.
Files:
src/auth/openai.tssrc/auth/openai.test.ts(or add if missing)
Acceptance:
- Stored OpenAI API key is written to
~/.config/flynn/auth.jsonwith0600permissions. - OAuth entry remains backward compatible.
Tests:
pnpm test:run src/auth/openai.test.ts
PR 3 — Anthropic auth store: add auth-token storage
Goal: allow auth_token to be stored and selected with auth_mode: oauth.
Checklist:
- Extend
src/auth/anthropic.tsauth store shape to includeauth_token. - Add functions:
loadStoredAnthropicAuthToken()storeAnthropicAuthToken(token)clearAnthropicAuthToken()getAnthropicAuthToken()
- Extend
src/auth/anthropic.test.ts.
Files:
src/auth/anthropic.tssrc/auth/anthropic.test.ts
Acceptance:
auth_tokencan be stored and resolved without being present in YAML.
Tests:
pnpm test:run src/auth/anthropic.test.ts
PR 4 — CLI commands for managing new stored credentials
Checklist:
- Add
flynn openai-keycommand (store API key in auth.json). - Extend
flynn anthropic-authto support storing either API key or auth token:- recommended:
flynn anthropic-auth --tokenORflynn anthropic-token
- recommended:
- Update
src/cli/index.tsregistration.
Files:
src/cli/openai-key.ts(new)src/cli/anthropic-auth.ts(modify)src/cli/index.ts
Acceptance:
- CLI can store credentials without printing them.
- Re-running commands detects existing stored credentials and exits cleanly.
Tests:
- Add targeted unit tests if the CLI layer has existing patterns; otherwise validate via integration tests where feasible.
PR 5 — TUI /login UX: OpenAI choice (OAuth vs API key) + Anthropic token
Checklist:
- Update
/login openaiinsrc/frontends/tui/minimal.ts:- Present a simple prompt: "1) OAuth device flow 2) Paste API key"
- Store selected credential via auth store
- Add
/login anthropicinsrc/frontends/tui/minimal.ts:- "1) Paste API key 2) Paste auth token"
- Keep existing
/login githuband/login zaibehavior intact.
Files:
src/frontends/tui/minimal.tssrc/frontends/tui/commands.ts(if command parsing needs to accept new provider)
Acceptance:
- TUI can store OpenAI API key or OAuth token.
- TUI can store Anthropic API key or auth token.
Tests:
- Add or extend minimal TUI tests as needed (existing suite patterns exist for model switching).
PR 6 — Model factory: enforce auth_mode per tier
This is the core runtime change.
Checklist:
- Update
src/daemon/models.ts:- Read
cfg.auth_mode(or inferred fromuse_oauth) per tier. - For OpenAI:
auth_mode=oauth: configureOpenAIClient({ useOAuth: true })and verify OAuth tokens exist.auth_mode=api_key: configureOpenAIClient({ apiKey: resolvedKey }).
- For Anthropic:
auth_mode=oauth: require auth token (config/env/store).auth_mode=api_key: require API key (config/env/store).
- For other providers:
- define behavior explicitly (likely
api_keyonly unless provider already supports token-style auth).
- define behavior explicitly (likely
- Ensure error messages name the expected auth type and remediation.
- Read
Files:
src/daemon/models.ts- potentially
src/models/openai.ts(if you decide to unify API key vs OAuth selection naming)
Tests:
src/daemon/clientFactory.test.ts- auth_mode precedence over use_oauth
- auto -> api key path
- oauth -> token path
- correct failures when missing
Acceptance:
- Selecting
auth_modechanges runtime behavior deterministically.
PR 7 — Doctor: report auth source availability
Checklist:
- Extend
checkModelConnectivityinsrc/cli/doctor.tsto reflectauth_mode:- If
auth_mode=api_key, warn/fail when API key is absent from config/env/store. - If
auth_mode=oauth, warn/fail when OAuth/token is absent. - If
auth_mode=auto, keep current behavior but improve messaging.
- If
- Add tests in
src/cli/doctor.test.ts.
Acceptance:
- Doctor output tells user what to do next (command name + env var) without exposing secrets.
Final Integration Checks
pnpm typecheckpnpm test:run- Update
docs/plans/state.jsonentry for this checklist once implemented (status, summary, test status).