# plugin_copilot_login An open-source **SCORPIOX BOT** plugin for **GitHub Copilot** device-code login and token management on your own node. It is a single zero-dependency C99 binary that runs as a node plugin: it starts the GitHub OAuth device flow, shows the one-time code on a page you can open from anywhere, polls GitHub until you approve the code on any device, then reports your session state and the expiry of the derived Copilot token - and refreshes that token on demand. ``` node github.com ---- ---------- plugin_copilot_login --start--> scorpiox-copilot-login POST /login/device/code <-- user_code 1234-5678, device_code page shows the code | you type it on any device -----------> approve plugin_copilot_login --poll--> scorpiox-copilot-login POST /login/oauth/access_token <-- access_token gho_... writes ~/.copilot/.credentials.json ``` ## Why it never holds a secret GitHub's device flow still carries an OAuth **client id**, and a token exchange is an HTTPS POST. A public repository must never ship either a client secret or TLS client code that pretends to be one. So this plugin does not speak TLS at all: it drives the `scorpiox-copilot-login` CLI that ships with SCORPIOX CODE, in its documented machine mode (`SXLOGIN-MACHINE-V1`, one JSON line per call), and reads only the files that CLI writes. What that buys you: * **No token ever reaches a response.** Every JSON field is token *presence* and *expiry*. The refresh action inspects the CLI's payload for the `access_token` key and throws the payload away; the new state is proven by re-reading the cache file, never by the CLI's word. * **Nothing is trusted from the browser.** The user code is relayed verbatim, the account name is validated against a shell- and path-safe alphabet, and the CLI path comes from an environment variable the node owner sets, never from a query string. * **The page is self-contained.** No CDN, no external asset, a CSP that forbids remote scripts, and no `Content-Length` header (the fronting proxy rejects it). ## Install ### 1-click, pre-compiled Browse **https://botmarket.scorpiox.net** and install *GitHub Copilot Login*, or fetch a pre-built binary directly: ```sh # universal static Linux (Alpine, Debian, Ubuntu, Arch, Omarchy) curl -fsSL https://dist.scorpiox.net/bot-plugins/copilot-login/latest.json mkdir -p ~/.scorpiox/plugins curl -fsSL -o ~/.scorpiox/plugins/plugin_copilot_login \ https://dist.scorpiox.net/bot-plugins/copilot-login/1.0.1/linux-x86_64-musl/plugin_copilot_login chmod 0755 ~/.scorpiox/plugins/plugin_copilot_login ``` The bot picks the plugin up on its next scan; no server restart. ### Compile from source ```sh git clone https://plugingit.scorpiox.net/scorpiox-bot-plugin-copilot-login.git cd scorpiox-bot-plugin-copilot-login make # native Linux/macOS make musl # static x86_64, the universal Linux artifact make arm64 # static aarch64 (Raspberry Pi 5, ARM servers) make win64 # static Win64 PE (MinGW-w64) make install # copy into ~/.scorpiox/plugins ``` On Windows, from PowerShell: ```powershell powershell -ExecutionPolicy Bypass -File build.ps1 ``` The binary has no runtime dependencies. `make test` runs the offline suite. ## Modes ### 1. Discovery ```sh ./plugin_copilot_login --meta {"name":"copilot","desc":"Copilot login"} ``` Reachable without a password and without touching any credential file. The bot uses it to list the plugin. ### 2. JSON API All callbacks are `?action=...` and answer with one JSON object. `format=json` alone means `status`, and `?name=` targets a named account. | Action | What it does | |--------|--------------| | `status` | Reads the credentials file, `config.json`, the token cache and the account directory; also asks the CLI. Answers `logged_in`, `user`, `account`, `pending`, `expired`, `expires_in_sec`, `scope`, `accounts`. | | `start` | Starts the device flow. Answers `flow`, `verify_url`, `user_code`, `interval`, `expires_in`. | | `poll` | One non-blocking poll. Answers `state:"pending"`, or `state:"done"` with the fresh status once you approve on GitHub. | | `cancel` | Drops the pending flow. | | `refresh` | Derives a fresh Copilot token through the CLI and re-reads the cache. Answers `refreshed:true` plus the new status. | | `accounts` | Lists the named account files and which one is active. | ```sh curl -s -H "X-Bot-Password: $BOT_PASSWORD" \ 'http://127.0.0.1:8150/plugin_copilot_login?action=status' ``` ```json {"ok":true,"logged_in":true,"user":"octocat","account":"default", "pending":false,"expires_in_sec":1740,"expired":false,"cache_present":true, "cli_present":true,"scope":"read:user","profile":"claude-sonnet-5", "accounts":[{"name":"work","logged_in":true,"expires_in_sec":1740,"expired":false}], "flow":"device_code","protocol":"SXLOGIN-MACHINE-V1"} ``` ### 3. HTML page `GET` (or `?embed=1`) returns the responsive page: a connection pill, a GitHub user badge, the device-flow card with a large user code and a **Copy Code & Open GitHub** button, a live polling indicator that re-checks `action=poll` every `interval` seconds, a named-account switcher, and a refresh button. It follows the bot's theme through the standard handoff, works down to 390 px and inside the Chat floating window. ## Files it reads | Path | Purpose | |------|---------| | `~/.copilot/.credentials.json` | `github_token` (`gho_...`), `scope`, `timestamp` | | `~/.copilot/config.json` | `lastLoggedInUser.login` - the only place the GitHub user name lives | | `~/.copilot/.copilot-token-cache.json` | derived Copilot token and its `expires_at` | | `~/.copilot/accounts/.json` | named accounts, same shape as the credentials file | | `~/.claude/.login-pending/copilot-.json` | the pending device flow, written by the CLI | | `~/.claude/scorpiox-env/copilot.txt` | the `PROVIDER=copilot` profile written by `--create-profile` | Every one of these is overridable for deterministic offline testing: ``` COPILOT_CREDS_PATH COPILOT_ACCOUNTS_DIR COPILOT_PENDING_DIR COPILOT_ENV_DIR COPILOT_LOGIN_BIN COPILOT_REFRESH_BIN ``` ## Screenshots | 1440 dark | 390 light | |---|---| | ![1440 dark](docs/ui-1440-dark.png) | ![390 light](docs/ui-390-light.png) | | Device flow | 390 dark | |---|---| | ![flow](docs/ui-flow-dark.png) | ![390 dark](docs/ui-390-dark.png) | Regenerate with `python3 tests/e2e.py` (Playwright drives the real page at 1440 / 1024 / 390 px in both themes). ## Tests `tests/run.sh` is fully offline: it points both CLIs at `tests/mock_login.sh` and `tests/mock_refresh.sh`, keeps every credential path inside a throwaway directory, and proves 119 assertions - the metadata contract, the 401 gate, all six actions including the pending/done/denied poll states, the named-account scan, the refresh-failure path, the HTML page contract and a source audit for secrets, LAN addresses, `Content-Length` and emoji. ```sh make test ``` ## Security model Read this before installing anything that runs as a plugin. * The plugin executes **native code** with the node user's full OS permissions. * It spawns two child processes (`scorpiox-copilot-login`, `scorpiox-copilot-refreshtoken`). Those children talk to GitHub over TLS; this plugin does not open a socket of its own. * It **never** prints, logs or returns a token. A missing `gho_` token is reported as `logged_in:false`, not as an empty field you could mistake for a live session. * It performs no destructive action. The only write paths are the ones the CLI owns; `cancel` removes a pending marker file and nothing else. ## License MIT. Copyright (c) 2026 SCORPIOX INC. Source: https://plugingit.scorpiox.net/repo?name=scorpiox-bot-plugin-copilot-login Registry: https://dist.scorpiox.net/bot-plugins/copilot-login/