Commit Graph
4 Commits
Author SHA1 Message Date
yetone d0c1afeffd signin: a sign-in's address pasted into the Import box finishes that sign-in (LuvLetter)
LuvLetter on Discord runs magpie in Docker (`magpie web`). ChatGPT sent
the browser back to http://localhost:1455/auth/callback?code=…&state=…,
which the browser couldn't reach, and the address went into "Import
from a file instead…" rather than the sign-in's Callback URL field.
Opening that box canceled the waiting sign-in, and the import read the
address as a refresh token, sent it to ChatGPT, and said "ChatGPT
didn't take the refresh token — it has been used since…".

- The Import box keeps a sign-in that takes a pasted address waiting
  behind it (signing.behind in app.js); Done, Cancel or a new sign-in
  end it. One that takes no address is canceled as before.
- POST /api/signin/import first takes out each text that is a browser
  sign-in's end (an http(s) address with code or error and a state, or
  Claude's code#state) and finishes the sign-in whose state it carries
  through SubmitSignInCallback, as the Callback URL field does
  (provider.PastedSignIns). The rest is imported as before.
- An address for no waiting sign-in fails with a reason that says where
  such an address goes, and is never sent to a vendor.
- ImportLogins (Codex/Claude) and the Google import's line parsers
  refuse a line with :// as "not a refresh token": the CLI import too.

Siblings: matching is by the OAuth state of every waiting sign-in
(signIns.m), so ChatGPT, ChatGPT API, Gemini/Antigravity, plugin
sign-ins and Claude (address or code#state) are all covered.

Run:
- go test -tags nogui ./internal/provider (-skip
  TestUnreadLoginsWriteErrorsKeepCredentials, #3632 crashes the package
  on main), ./internal/usage ./internal/usageapi ./internal/probelog
  ./internal/gui ./internal/cli: ok, at e111e08aa plus this change.
- New TestImportBoxFinishesThePastedSignIn (fake token endpoint, counts
  trades: another sign-in's state 0, the address 1, again still 1),
  TestImportBoxFinishesAPastedClaudeCode, TestImportTellsAddressesFromAccounts.
- signin-paste-import.test.cjs, en and zh, Chromium and WebKit: 6/6;
  with the other sign-in/login/import GUI files and i18n-keys.
- gofmt -l; go vet darwin, GOOS=linux -tags nogui, GOOS=windows.
- Reproduced in a sandbox `magpie web`: the ChatGPT sign-in shows its
  Callback URL field, and opening the Import box canceled it.

Broken by hand: looksLikeAddress returning false makes
TestImportTellsAddressesFromAccounts fail with the user's exact message;
signInByState returning nil fails the two finish tests; dropping
signing.behind fails the GUI test ("the sign-in waits behind the box,
not canceled").

Not tried: a real ChatGPT code exchange (tests never reach OpenAI); the
full go test ./... (other sessions' suites were on this machine).
2026-10-27 15:21:10 +08:00
yetone 8c5b9f928d provider, agent, gui: subscription accounts can be turned off, and then no agent's sign-in is read (#1535, MaxHaiCom)
What changed: Settings → Privacy → Subscription accounts (On/Off),
`magpie accounts discovery [on|off]` and MAGPIE_NO_ACCOUNTS=1 turn off
account discovery. It stays on by default. While it is off, magpie reads
none of the agents' sign-ins: ~/.claude/.credentials.json, .claude.json's
account, ~/.codex/auth.json, Copilot's, Cursor's, Devin's, Kiro's,
Gemini's, ZCode's, Command Code's and OpenCode's files. It runs no
`security` / `secret-tool` for the Keychain or Secret Service, and asks no
agent CLI who is signed in. It serves no subscription. API-key providers,
middleware plugins and Pi extensions work as before.

Why: the reporter runs magpie on machines where reading other tools'
credentials isn't wanted. The owner delegated the call.

How: settings.NoAccountDiscovery (kept per computer by KeepOwn) and
settings.AccountDiscoveryOff(). The variable only ever turns discovery
off. The gates sit at every reader (readAccountFile, discoveryOff) and at
every route that reads or writes a sign-in, so a route that skips
Accounts still reads nothing:
- Accounts, All, Logins, usage, renewal, warm-up, session identities,
  check-ins;
- switching, forgetting, SetLoginOn, StartSignIn, the imports;
- moves onto plugins.
The ones that write refuse with an error that names how to turn it back
on. On the agent side, Agent.Source and OpenCode's auth.json are gated,
and Codex wiring goes by magpie's stash instead of auth.json, so a
toggle never rewires Codex. logins.json and plugin-auth.json are left
untouched and serve again when discovery is turned back on. A change
applies at once (ForgetAccounts).

Docs: providers-accounts.md, README (en, zh-CN), and the site's CLI table
(en, zh, ja).

Run:
- TestAccountDiscoveryOffReadsNoSignIn (provider) and
  TestAccountDiscoveryOffAgentsReadNoSignIn (agent). Every credential
  path is a FIFO that records each open, and security, secret-tool,
  claude, codex, cursor-agent, devin, kiro-cli, copilot and grok are fakes
  on PATH. Both fail with the gate removed: they show the opens and
  `security find-generic-password -s Claude Code-credentials`, among
  others. Both pass with the gate in place.
- TestAccountDiscoverySetting and TestAccountsDiscoveryCmd.
- account-discovery.test.cjs: chromium and webkit, 900 and 360 wide,
  en/zh/zh-TW/ja/de, 32/32. The neighbouring privacy, redact,
  settings-sections and i18n-keys GUI tests: 49/49.
- The full `go test -tags nogui ./...`, gofmt -l, and go vet for darwin,
  linux and windows on the touched packages.

Not tried: a real machine under fs_usage, and Linux and Windows at
runtime. The FIFO tests are !windows.
2026-10-11 06:38:40 +08:00
yetone f2611b7154 accounts: import ChatGPT accounts from Cockpit Tools' and Sub2API's exports, several files at once, from the window or magpie accounts import; the box says the source tool is signed out (#1453)
wlj521 asked for cockpit-tools' import: several auth.json files at once.
magpie's window already imported Codex's auth.json and CLIProxyAPI's
files; this brings it the rest of what Cockpit Tools exports and a command
for it.

What changed:
- login_import.go reads Sub2API's export ({accounts: [{platform, type,
  credentials}]}), so every Cockpit Tools export format comes in (its own,
  auth.json, CPA, Sub2API). An API key, another vendor's account and an
  entry with only an access token (a web session: it can't be renewed and
  would stop within days) are refused with the reason.
- ImportLogins and ImportGoogleAccounts no longer skip one file of several
  that holds no account: it is a failed row with its place
  (ImportedAccount.File), which the window and the command name by file.
- `magpie accounts import <codex|claude|antigravity|factory> <file>...
  [--yes]`: says first what importing does to the tool the file came
  from, imports nothing without a yes, only reads the files, and lists
  each account's outcome.
- The window's import box names Cockpit Tools and Sub2API and says
  plainly that the source tool is signed out of the account and the file
  is only read. Claude's box no longer claims a refresh it doesn't do.
  zh, zh-TW, ja and de for every new string; the retired strings removed.
- docs: reference.md and providers-accounts.md describe the import.

Decision: keep the refresh on import. It checks the file and makes magpie
the token's one holder at a moment the user chose. Storing the token
as-is, as Cockpit Tools does, only delays the rotation conflict and makes
which side gets signed out a race.

Run:
- go test -tags nogui ./... under a sandbox HOME (pinned caches)
- TestImportCockpitExports red on the old login_import.go (Sub2API rows
  unread, the garbage file passed over); TestAccountsImport red with the
  confirmation removed by hand; login-import.test.cjs red on the old app.js
- node --test login-import, factory-key, i18n-keys, gui-ja, gui-de,
  gui-zh-tw (Chromium and WebKit; en and zh, results at 380px)
- gofmt -l; go vet, GOOS=linux and GOOS=windows go vet -tags nogui on .
  and ./internal/provider; darwin, linux and windows builds
- no live ~/.codex: fixtures and a fake token endpoint only
2026-10-10 10:56:55 +08:00
yetone 356549710b subscription: Antigravity accounts can be imported from a JSON file (莫: https://github.com/jlcodes99/vscode-antigravity-cockpit 这个开源的里面有 你可以看看) — beside Add account (and as "Import instead…" on the risk note) the Antigravity card takes files or pasted text exported by Antigravity Cockpit (a JSON array of {email, refresh_token}, or refresh tokens one a line), Antigravity Manager (the same array, {accounts:[…]}, or an account file with token{refresh_token, email, project_id}) and CLIProxyAPI (an antigravity auth file, type/email/refresh_token/project_id; another type's is refused). All three sign in with the Antigravity app's own OAuth client, as magpie does, so their refresh tokens are good here. Each account is checked as signing in does: the token refreshed at Google, the email read from userinfo (the file's if that's refused), the project and plan from loadCodeAssist, then kept in logins.json like a signed-in account. A token magpie already has is not sent again (exists); a known email with a new token replaces the old (updated); duplicates in the file, entries with no token and tokens Google refuses are reported per account, Google's bare "Bad Request" explained. POST /api/signin/import; tokens are never logged, shown or returned, and the paste box is masked. Tested against an httptest token/userinfo/Code Assist server in a sandbox HOME 2026-09-29 00:52:09 +08:00