Description
When opencode web is run behind a reverse proxy (e.g. exposed at
https://opencode.example.com), OAuth flows that rely on a callback URL
cannot complete. The codex plugin (ChatGPT subscription auth) starts a
side-listener on 127.0.0.1:1455 (packages/opencode/src/plugin/codex.ts,
OAUTH_PORT = 1455) and uses
redirect_uri=http://localhost:1455/auth/callback. The browser running the
auth flow is on the user's own machine, not the opencode server, so:
- The redirect lands on the user's
localhost:1455, where nothing is
listening.
- The listener inside the opencode container binds to loopback, so even if
Docker -p 1455:1455 were added, it can't be reached. SSH tunnels also
fail unless the bind is 0.0.0.0 and ports are published — none of which
is reasonable to ask web-UI users to set up per-session.
- The headless/device-code mode added in 1.14.x works for some, but is
blocked by SSO/IdP policies in some orgs.
Proposed change
For opencode web deployments, the OAuth callback should be served by the
opencode web server itself, at the externally-reachable URL the user is
already using:
- Public URL config, e.g. env var
OPENCODE_PUBLIC_URL (or config field
server.publicUrl). Could also be auto-detected from the request that
initiated the OAuth flow (X-Forwarded-Host / X-Forwarded-Proto or
Host).
- Serve the callback on the web server, not a side-listener. When
OPENCODE_PUBLIC_URL is set, OAuth flows started from the web UI use
${OPENCODE_PUBLIC_URL}/auth/callback as redirect_uri and the opencode
web server (port 4096) handles that path, replacing the
localhost:1455 listener for this deployment mode.
External constraint
Per #8798's investigation, the OpenAI OAuth client used by opencode has its
redirect URI locked to http://localhost:1455/auth/callback. Making the
above usable for ChatGPT auth requires one of:
- Registering additional URIs / a wildcard with OpenAI on opencode's OAuth
app.
- An opencode-hosted relay endpoint that accepts the callback and forwards
the code to the user-supplied URL via state (similar to how some OAuth
proxies work).
Other providers (Anthropic, GitHub Copilot) already work fine via paste-code
/ device-code and aren't affected.
Use case
Self-hosted opencode web in Docker behind a reverse proxy at a public URL;
shared by one or more users from their normal browser. OAuth must complete
without SSH tunnels, port forwarding, or copying auth.json from a
workstation.
Related
Description
When
opencode webis run behind a reverse proxy (e.g. exposed athttps://opencode.example.com), OAuth flows that rely on a callback URLcannot complete. The codex plugin (ChatGPT subscription auth) starts a
side-listener on
127.0.0.1:1455(packages/opencode/src/plugin/codex.ts,OAUTH_PORT = 1455) and usesredirect_uri=http://localhost:1455/auth/callback. The browser running theauth flow is on the user's own machine, not the opencode server, so:
localhost:1455, where nothing islistening.
Docker
-p 1455:1455were added, it can't be reached. SSH tunnels alsofail unless the bind is
0.0.0.0and ports are published — none of whichis reasonable to ask web-UI users to set up per-session.
blocked by SSO/IdP policies in some orgs.
Proposed change
For
opencode webdeployments, the OAuth callback should be served by theopencode web server itself, at the externally-reachable URL the user is
already using:
OPENCODE_PUBLIC_URL(or config fieldserver.publicUrl). Could also be auto-detected from the request thatinitiated the OAuth flow (
X-Forwarded-Host/X-Forwarded-ProtoorHost).OPENCODE_PUBLIC_URLis set, OAuth flows started from the web UI use${OPENCODE_PUBLIC_URL}/auth/callbackasredirect_uriand the opencodeweb server (port 4096) handles that path, replacing the
localhost:1455listener for this deployment mode.External constraint
Per #8798's investigation, the OpenAI OAuth client used by opencode has its
redirect URI locked to
http://localhost:1455/auth/callback. Making theabove usable for ChatGPT auth requires one of:
app.
the code to the user-supplied URL via
state(similar to how some OAuthproxies work).
Other providers (Anthropic, GitHub Copilot) already work fine via paste-code
/ device-code and aren't affected.
Use case
Self-hosted
opencode webin Docker behind a reverse proxy at a public URL;shared by one or more users from their normal browser. OAuth must complete
without SSH tunnels, port forwarding, or copying
auth.jsonfrom aworkstation.
Related