The remote callback endpoint added in #716 cannot be authenticated: the
browser reaches /auth/callback on the far end of the user's own tunnel,
a different origin from the DeepTutor Web session, so no cookie is sent.
The user ContextVar is only ever set inside require_auth, which left
get_codex_oauth_service() resolving every callback to the default root
while the login operation lived under data/users/<id> — so remote Codex
sign-in returned login_not_active for every non-administrator.
Deliver by OAuth state instead. The state is a secret this process
minted for exactly one login and is compared in constant time, which is
already the trust model the loopback listener uses; no new authorization
surface is opened. Delivery keeps the endpoint's existing status codes:
409 when nothing is waiting, 400 when a login is waiting but the state
does not match.
The PR's endpoint tests monkeypatched the service factory, so user
resolution was never exercised; they now patch the delivery seam, and
three service-level tests cover routing to a non-default instance.
For a remote or containerized deployment the browser's localhost is the
user's workstation while the OAuth listener runs on the server, so a
reverse proxy cannot deliver http://localhost:1455/auth/callback to that
private listener and Codex sign-in could never complete.
Keep the listener loopback-only and forward just the exact browser
callback path through the Web origin to a state-validating broker. The
settings card and CLI now show the real callback address, the SSH tunnel
command, an explicit authorize action and a countdown, and survive a page
reload; the deployment docs cover the Docker host-port and reverse-proxy
caveats.
The listener stays bound to loopback and ports 1455/1457 are never
published; the Web bridge rewrites only /auth/callback; the broker
requires an active operation and a constant-time state match; callback
responses are no-store HTML that never echo the code or state; PKCE and
the token exchange are unchanged. Binding the listener with
start_serving=False also closes a window where a connection could be
accepted before the callback object existed.