# plugin_codex_login **OpenAI Codex Login** - a SCORPIOX BOT open-source plugin that manages the OpenAI Codex OAuth session on your node: start a device-code login, read the one-time user code off the panel, watch the token expiry, list named accounts, and refresh the token on demand. One clean-room C99 binary, zero dependencies, no OAuth client secret, and no token ever leaves the node - or even the child process that fetched it. ``` --meta {"name":"codex","desc":"Codex login"} ?action=status session state, expiry, accounts (JSON) ?action=start begin the device flow -> verify_url + user_code ?action=start&force=1 replace an existing session ?action=poll one non-blocking check on the pending flow ?action=cancel drop the pending flow ?action=refresh refresh the token now ?action=accounts the same status, account list included ?format=json same as action=status GET (no action) responsive dark/light HTML UI ``` Every action accepts `&account=` to work on a named account instead of the default one. ## Design: the plugin drives the CLI, it never speaks TLS A Codex device-code exchange is a sequence of HTTPS POSTs to OpenAI. A public clean-room repository must not carry a client secret or a vendored TLS stack, so this binary makes no network request at all. It runs the node's own login tool through the SCORPIOX CODE machine-mode contract - `--status`, `--start`, `--poll`, `--cancel`, one JSON line per call - and reads the files that tool writes: ``` ~/.codex/auth.json default account ~/.codex/accounts/.json named accounts ~/.claude/.login-pending/codex-.json pending device flow ~/.claude/scorpiox-env/codex.txt the profile the CLI creates ``` ## Where the expiry comes from `auth.json` has no expiry field. The access token is a JWT, and a JWT carries its lifetime in the `exp` claim of its base64url payload, so the plugin decodes that payload with its own twelve-line decoder and reports the countdown from it. That is what makes the panel useful on a node where SCORPIOX CODE is not installed: the file is still readable, the countdown is still real, and the login CLI's own `expires_at: 0` never overwrites a computed value. `last_refresh` in the same file is an ISO-8601 UTC stamp and is reported as unix seconds. ## Environment overrides | Variable | Default | Meaning | |---|---|---| | `CODEX_CREDS_PATH` | `~/.codex/auth.json` | credential file; also anchors the account and profile paths | | `CODEX_ACCOUNTS_DIR` | `~/.codex/accounts` | named account directory | | `CODEX_PENDING_DIR` | `~/.claude/.login-pending` | pending-flow marker directory | | `CODEX_ENV_DIR` | `~/.claude/scorpiox-env` | profile directory | | `CODEX_LOGIN_BIN` | `scorpiox-codex-login` | login CLI | | `CODEX_REFRESH_BIN` | `scorpiox-codex-refreshtoken` | refresh CLI | | `CODEX_ACCOUNT` | (unset) | account to operate on when no `?account=` is given | A relocated `CODEX_CREDS_PATH` implies a relocated `.codex` tree: the same CLI writes the account files and the profile into one directory, so reading one from the override and the rest from `$HOME` reports an empty state for a session that has one. The pending markers are the exception on purpose - they belong to the bot's own contract, not to the provider, and stay under `~/.claude/.login-pending` where every SCORPIOX CODE login tool puts them. Setting `CODEX_LOGIN_BIN` and `CODEX_REFRESH_BIN` to throwaway scripts is how `tests/run.sh` exercises the whole contract offline, with no network and no real Codex session. ## Auth The node API on `:8150` must never be open to the LAN. `--meta` stays unauthenticated so discovery works; every other route requires `X-Bot-Password`, `Authorization: Bearer `, or `?pwd=` when the node has `BOT_PASSWORD` set. ```bash curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:8150/plugin_codex_login # 401 ``` ## HTTP header rule This binary never emits a `Content-Length` header. It sits behind Caddy, which returns 502 when a CGI response announces a length that does not match the body. Every response here is written with `Cache-Control: no-store` and no declared length, and the test suite fails if the string `Content-Length` ever appears in the source. ## Build ```bash make # native -> ./plugin_codex_login make musl # static musl x86_64 (universal Linux artifact) make arm64 # static aarch64 (Raspberry Pi 5 / ARM64 servers) make win64 # MinGW-w64 static PE make macos # Apple clang (run on macOS) make test # build + tests/run.sh make ui # regenerate src/ui_html.h from src/ui.html ``` `make ui` is required after editing `src/ui.html`: `tools/gen_ui.py` turns the page into a C string with two control-byte placeholders (`0x01` = the bot theme prepaint plus the token block, `0x02` = the theme handoff script). Keeping the palette in `src/bot_theme_plugin.h` means a plugin page can never drift from the theme of the bot it lives inside. On Windows, `build.ps1` does the same thing with MinGW-w64 and checks that the output really starts with `MZ` before calling the build a success. ## Install ```bash make install # copies the binary into ~/.scorpiox/plugins (or /workspace/...) ``` Or drop `plugin_codex_login` (`.exe` on Windows) into `~/.scorpiox/plugins/`. SCORPIOX BOT discovers it on the next request with no restart. ## Tests ```bash make test # or: sh tests/run.sh ``` `tests/run.sh` is fully offline. It builds the binary if needed, points the credential paths and both CLIs at fixtures in a temporary directory, and checks the public contract: the exact `--meta` string, the 401 gate on every action, JWT expiry decoding, the pending-marker TTL, named accounts, the device-flow actions, the refresh action, the shape of the HTML page, and a full-git-history scan for secrets, LAN addresses and machine names. ## License MIT. Copyright (c) 2026 SCORPIOX INC.