Commit Graph
1 Commits
Author SHA1 Message Date
yetone ffc69f0244 codex: an account can keep its access token only, never renewed (EastonXvii on X)
A Codex account can now be imported, or ticked later, as "Access token
only". magpie uses the access token it was given and never refreshes it.
The refresh token is never spent or rotated, so another computer signed
in to the same ChatGPT account stays signed in.

- Every renewal of a saved account goes through renewSaved. For an
  access-only account it calls accessOnlyToken, which hands out the
  token until it runs out and never calls codexRefresh. That covers
  requests, usage reads, the idle read, models, resets, warm-up, the
  401 recovery and the keep-alive, which also skips such accounts.
- Once the token runs out, the account is marked Lapsed with
  refreshRefused. The provider editor shows "Access expired" and
  "Import again", which opens the import with the tick set. A new
  import or sign-in replaces the entry and clears both.
- Such an account is never switched into Codex, since Codex would
  renew it. That applies to switchable, switchSavedLogin, NextLogin,
  keep-as and signInToFirst. The live or held account can't be made
  access-only (errAccessOnlyHeld). Its row says "magpie only".
- Import: ImportCodexAccessOnly accepts files that have only an access
  token, refuses an expired token or a missing id_token, and makes no
  refresh call. CLI: `magpie accounts import codex --access-only`,
  `magpie accounts access-only codex <email> [on|off]`. GUI: the
  import box tick, the row tick and POST /api/login/access-only|renewed.
- The core scripts stay within budget: app.js is smaller than main's.
  This change's own comments and nine sign-in/import comment blocks were
  cut, with no raise.

Run (on mote):
- gofmt -l clean; go vet for darwin, linux (nogui) and windows ok.
- go test ./internal/provider ./internal/cli ./internal/gui ok.
- GUI files in chromium and webkit, en and zh: codex-access-only (new),
  login-import, account-return, i18n-keys, account-row-line,
  agent-switch-accounts and signin-paste-import: 64/64 at the final
  tree. In an earlier grouped run, signin-paste-import failed once on its
  Import button's wait. It then passed 6/6 alone and in the rerun.

Broken by hand:
- With the renewSaved branch and the keep-alive skip taken out,
  TestCodexAccessOnlyNeverRefreshed went red: the keep-alive renewed
  the account. TestCodexAccessOnlyRunOutLapses went red too: a run-out
  token was handed out.
- With the branch and the import path taken out, a forced renewal went
  through and an expired-token import was "added". Both tests went red.

Not tried: a real ChatGPT account, so I did not check that another
computer stays signed in. No Windows run, since nothing here differs by
OS.
2026-11-10 09:49:30 +08:00