|
| 1 | +# 001 — Current-state inventory of every login surface |
| 2 | + |
| 3 | +Read at `bb89eafbe`. Every claim below is a file:line read, not a memory. |
| 4 | + |
| 5 | +## Three surfaces, three renderers |
| 6 | + |
| 7 | +There are three places a human can start an OAuth login in the GUI, and they |
| 8 | +do not share a renderer. |
| 9 | + |
| 10 | +### A. Workspace auth panel — an already-added provider |
| 11 | + |
| 12 | +`gui/src/components/provider-workspace/ProviderAuthPanel.tsx` |
| 13 | + |
| 14 | +- `:242` picks the hint for this row: `loginHint?.provider === item.name`. |
| 15 | +- `:392-401` renders the device code with a copy button. |
| 16 | +- `:402` renders `<LoginUrlBlock url={hintForThis.url ?? ""} />`. |
| 17 | +- `:403-408` renders Cancel. |
| 18 | +- A search for `paste`, `manual`, or `submitManual` across all 568 lines |
| 19 | + returns nothing. **This surface cannot accept a pasted code.** |
| 20 | + |
| 21 | +### B. Add-provider modal, OAuth pane — a first add via a catalog preset |
| 22 | + |
| 23 | +`gui/src/components/add-provider-oauth-pane.tsx` |
| 24 | + |
| 25 | +- `:59` renders `<LoginUrlBlock url={oauthUrl} />`. |
| 26 | +- `:60-99` renders the paste input and submit button. |
| 27 | +- No device code is rendered anywhere. The prop does not exist. |
| 28 | +- When a device flow returns no `url`, `LoginUrlBlock` returns `null` |
| 29 | + (`login-url-block.tsx:16`), so the pane shows a spinner label and an empty |
| 30 | + paste box with nothing to act on. |
| 31 | + |
| 32 | +The hook behind it, `gui/src/components/use-add-provider-oauth.ts:53`: |
| 33 | + |
| 34 | +```ts |
| 35 | +const data = await res.json() as { url?: string; instructions?: string; error?: string }; |
| 36 | +``` |
| 37 | + |
| 38 | +`deviceCode` is not in the type and is never read, although |
| 39 | +`src/server/management/oauth-account-routes.ts:176` returns it: |
| 40 | + |
| 41 | +```ts |
| 42 | +return jsonResponse({ url: authUrl, instructions, deviceCode }); |
| 43 | +``` |
| 44 | + |
| 45 | +### C. Add-provider modal, Accounts tab — a first add via an account row |
| 46 | + |
| 47 | +`gui/src/components/provider-catalog/ProviderCatalog.tsx:148-212` |
| 48 | + |
| 49 | +The account rows call `onLogin(row.id)`, which is `Providers.tsx`'s |
| 50 | +`requestLoginOAuth`. That path stores the hint: |
| 51 | + |
| 52 | +- `gui/src/pages/use-providers-oauth.ts:93-96` reads `url`, |
| 53 | + `instructions` **and** `deviceCode`, then calls `setLoginInfo`. |
| 54 | +- `gui/src/pages/Providers.tsx:365` passes `loginInfo` to |
| 55 | + `ProviderDetails` → `ProviderAuthPanel`. |
| 56 | + |
| 57 | +`ProviderAuthPanel` is the workspace surface for an **existing** provider. |
| 58 | +During a first add the modal is open and no panel is mounted for that |
| 59 | +provider, so the hint has no renderer. The row renders |
| 60 | +`t("prov.waitingBrowser")` and a Cancel button, and that is all the operator |
| 61 | +gets: no URL, no code, no paste box. |
| 62 | + |
| 63 | +**This is pain point 1 exactly.** The data arrives; nothing draws it. |
| 64 | + |
| 65 | +### D. Codex account modal — a fourth, near-duplicate surface |
| 66 | + |
| 67 | +`gui/src/components/add-codex-account-waiting-step.tsx:38-69` renders |
| 68 | +`LoginUrlBlock` plus its own paste input against |
| 69 | +`/api/codex-auth/login/code`. `src/codex/auth-api.ts:2077` returns only |
| 70 | +`{ flowId, url, instructions }` — no device code on this path either. |
| 71 | + |
| 72 | +## What each provider actually returns |
| 73 | + |
| 74 | +`startLoginFlow` (`src/oauth/index.ts:1420-1504`) resolves |
| 75 | +`{ url, instructions?, deviceCode? }` from the provider's `onAuth` call. |
| 76 | + |
| 77 | +| Provider | Shape | Produced at | |
| 78 | +|----------|-------|-------------| |
| 79 | +| xAI, Anthropic, ChatGPT, Cursor, Antigravity, Kiro | browser redirect + loopback callback | `OAuthCallbackFlow.login()`, `callback-server.ts:116` | |
| 80 | +| Kimi | device flow | `kimi.ts:212` — `instructions: "Enter code: …"`, **no `deviceCode` field** | |
| 81 | +| Nous | device flow | `nous.ts:660-663` — sets `deviceCode: device.userCode` | |
| 82 | +| GitHub Copilot | device flow | `github-copilot.ts:393-402` — locally constructed verify URL, `deviceCode: device.userCode` | |
| 83 | +| local-token import | no browser | `index.ts:1473` resolves `{ url: "" }` with an explanatory string | |
| 84 | + |
| 85 | +Two observations that matter for WP2: |
| 86 | + |
| 87 | +1. Kimi puts the user code inside a free-text `instructions` string instead of |
| 88 | + the structured `deviceCode` field, so no surface can render it as a code. |
| 89 | +2. `github-copilot.ts:170` refuses to trust `verification_uri_complete` and |
| 90 | + builds the URL itself. That invariant is not negotiable in WP4. |
| 91 | + |
| 92 | +## The manual-paste path, end to end |
| 93 | + |
| 94 | +1. `POST /api/oauth/login/code` — `oauth-account-routes.ts:202-213`. |
| 95 | + Caps input at 4096 chars, calls `submitManualLoginCode`, returns 409 on |
| 96 | + failure. |
| 97 | +2. `submitManualLoginCode` — `index.ts:1329-1360`. Rejects empty, rejects |
| 98 | + >4 KiB, rejects when no login is in progress, then `parseCallbackInput`. |
| 99 | + Rejects when no `code` is found; for `url`/`query` shapes enforces |
| 100 | + state once the flow has registered `expectedState`. |
| 101 | +3. `parseCallbackInput` — `callback-server.ts:273-300`. Three shapes: |
| 102 | + a parseable URL, a string containing `code=`, or a raw code with optional |
| 103 | + `#state`. |
| 104 | +4. `OAuthCallbackFlow.#waitForCallback` — `callback-server.ts:238-261` |
| 105 | + re-parses and loops on a bad paste. |
| 106 | + |
| 107 | +The flow **does** survive a rejected paste — the loop re-prompts. What it does |
| 108 | +not do is tell the operator anything useful: the GUI shows |
| 109 | +`t("prov.pasteFail", { error })`, and only surface B has a paste box at all. |
| 110 | + |
| 111 | +Accepted today: `https://…/callback?code=X&state=Y`, `?code=X&state=Y`, |
| 112 | +`code=X&state=Y`, `X`, `X#Y`. Whitespace is trimmed at three separate |
| 113 | +layers. A URL missing `state` is rejected with a specific message. |
| 114 | + |
| 115 | +## Server-side browser opening |
| 116 | + |
| 117 | +`oauth-account-routes.ts:170-175`: |
| 118 | + |
| 119 | +```ts |
| 120 | +if (authUrl && !deviceCode) { |
| 121 | + const { openUrl } = await import("../../lib/open-url"); |
| 122 | + openUrl(authUrl); |
| 123 | +} |
| 124 | +``` |
| 125 | + |
| 126 | +Unconditional for browser flows. `src/codex/auth-api.ts:1844` does the same |
| 127 | +on the Codex path. `src/lib/open-url.ts:11-24` spawns the platform opener, |
| 128 | +which resolves the **default** browser and therefore the default profile. It |
| 129 | +swallows spawn errors deliberately (a headless host emits ENOENT |
| 130 | +asynchronously), so a failed open is indistinguishable from a successful one |
| 131 | +from the GUI's perspective. |
| 132 | + |
| 133 | +There is no opt-out: no request field, no config key, no environment variable. |
| 134 | +Grepping `openUrl` finds callers in `login-cli.ts:85`, `dispatch.ts:305`, |
| 135 | +`auth-api.ts:1844`, and `oauth-account-routes.ts:173`; none is conditional. |
| 136 | + |
| 137 | +## Existing tests |
| 138 | + |
| 139 | +`tests/oauth-manual-code.test.ts` covers the paste path; |
| 140 | +`tests/oauth-callback-server.test.ts` and `oauth-callback-binds.test.ts` |
| 141 | +cover parsing and binding; `tests/github-copilot-oauth.test.ts`, |
| 142 | +`nous-oauth.test.ts`, `kimi-oauth-identity.test.ts` cover device flows; |
| 143 | +`tests/oauth-public-surface.test.ts` and `oauth-status-privacy.test.ts` |
| 144 | +cover the management surface and its redaction. |
| 145 | + |
| 146 | +Not covered anywhere: what the GUI *renders* during a login. Every gap in this |
| 147 | +unit lives in that hole. |
0 commit comments