Files
magpie/docs
yetone 12599e9cd0 signin: ChatGPT signs in by device code, the first way from another computer
curtinp118 on Discord runs magpie on a VPS and opens its web UI from home.
ChatGPT's browser sign-in comes back to localhost:1455, which is the
viewer's own computer. The page there won't load, and the box's main line
said "The account shows up here as soon as you're done", so the sign-in
looked broken. The fix until now was to copy the dead page's address back
by hand.

ChatGPT now also signs in by device code, as `codex login --device-auth`
does (codex-rs login/src/device_code_auth.rs). This is
startCodexDeviceSignIn, with StartSignInWith site "device":
- magpie asks auth.openai.com/api/accounts/deviceauth/usercode for a code
  with Codex's client id and headers;
- the box shows the code and https://auth.openai.com/codex/device;
- magpie polls deviceauth/token, where 403/404 means not entered yet, for
  up to 15 minutes;
- it then trades the authorization code at the token endpoint with the
  returned verifier and the /deviceauth/callback redirect.
Nothing listens on this computer.

The window starts this way when magpie web is opened from a host other
than localhost or loopback (remotePage in app.js). Either way, the box has
a link to the other way: "Sign in with a code instead" or "Sign in in the
browser instead". A device code that ChatGPT turns away (404) fails, and
that box links to the browser's way. Strings are in zh, zh-TW, ja and de.
providers-accounts.md describes the flow.

This went over TestCoreScriptBudget. It now fits with no raise
(1,533,700 of 1,533,802, on main's 1,533,789). The two way-switch
buttons share one helper (codexWay), and eight comments on the sign-in
code are cut down: openSignInPage, signingKept, startPluginSignIn, the
sign-in proxy, signInProxyChoices, Copilot's GHE.com, dropSigningIn and
renderStepPlan.

Run on mote (the pushed head is rebased on ae060550b):
- go test ./internal/provider: the new TestCodexSignInByDeviceCode,
  TestCodexDeviceSignInCanceled and TestCodexDeviceSignInOff, against a
  fake auth server that answers with the bytes auth.openai.com gave on
  11-03;
- go test -tags nogui ./internal/provider ./internal/backup (before the
  comment trim, which touched app.js only): ok; ./internal/gui
  ./internal/cli after it: ok;
- GUI at this head: signin-codex-device.test.cjs (new; Chromium and
  WebKit, en and zh, 420px wide), signin-paste-codex, signin-callback,
  signin-port-blocked, signin-paste-plugin, signin-paste-import, the
  sign-in proxy files and i18n-keys, 40 files: 591 pass, 0 fail;
- the whole GUI suite one commit earlier (base c86fa2a34; the rebase onto
  6a6e4fefa only brought in internal/sessions): two runs, each cut short
  when mote rebooted or by the owner's call not to wait. They got through
  1075 and 1395 cases, with 0 not ok;
- go vet ./..., GOOS=linux go vet -tags nogui ./..., GOOS=windows go vet
  ./..., the Linux nogui and Windows builds, and gofmt -l (base
  c86fa2a34).
Rebased on 4cd01c964 at last: go test -tags nogui ./internal/gui ok and
signin-codex-device, signin-paste-codex, signin-callback and i18n-keys
21 of 21. Before that, rebased on ae060550b with the comments cut: go test
-tags nogui ./internal/gui ok, ./internal/provider ok, and 40 sign-in,
proxy, i18n-keys and desktop-tiers GUI files: 594 pass, 1 fail. The red
was signin-proxy's chromium ja 380 proxy test. That file alone then
passed 3 runs, 120 of 120. It is #1814, open since 10-12 for this test
under load, and noted there. The step that failed wasn't kept.
The full go test ./... was not run, by the owner's rule.

On Linux (WSL magpie-desktop, sandbox HOME), magpie web listened on
0.0.0.0:3561 and was reached at the WSL IP. POST /api/signin
{"agent":"codex","site":"device"} got a real code from auth.openai.com
with url https://auth.openai.com/codex/device. The sign-in stayed waiting
across real polls for 12s, nothing listened on 1455, and cancel ended it.

Broken by hand:
- Taking the device branch out of begin() turned
  TestCodexSignInByDeviceCode and TestCodexDeviceSignInOff red.
- Taking the remotePage default out of startSignIn turned 8 of the 12
  signin-codex-device cases red.

Not tried:
- Entering the code with a real ChatGPT account, so a real token trade
  through the device callback hasn't been seen.
- Business/Enterprise workspaces that turn device codes off.

Also not changed: WorkBuddy's plugin sign-in already finishes by itself
from a remote browser (server-side poll; checked on the same WSL setup).
A backup still carries no sign-ins.

Reported by curtinp118 on Discord.
2026-11-03 09:54:05 +08:00
..