Sign-in, Accounts, Tokens and Agents
One deployment serves many people. Each person has an account (keyed by their numeric GitHub user id) and sees and changes only that account's backups, logs, chats and settings, through the dashboard, the API, the MCP server and the Observatory. The dashboard signs users in itself and keeps the session in an httpOnly cookie; browser JavaScript never sees a token.
- Sign in with GitHub: OAuth web flow with PKCE (S256). After GitHub confirms who signed in, the dashboard server asks the Go API for that person's account (
POST /api/internal/accounts/github). The API decides who may have an account (SIGNUP_MODE, section 3) and creates it on the first sign-in. - Username and password (fallback): the dashboard server forwards the form to the Observatory's
POST /auth/login(CHAT_USERNAME/CHAT_PASSWORD). This session always belongs to the deployment owner's account (account 1). - Personal access tokens (
ghb_pat_…, section 6): created on Settings > Access Tokens for scripts and MCP clients. - Agents (section 7): machines that run the backup worker for an account, linked with
github-backup-worker linkand approved on the dashboard's Link page. - Connect OpenRouter (optional, per user): OpenRouter's PKCE flow; the Observatory exchanges the code and stores the user's key.
Both sign-in methods end in the same session: an HS256 JWT signed with JWT_SECRET, with sub (the GitHub login or CHAT_USERNAME), account_id (the account, a JSON number), iss and aud (github-backup), iat and exp; GitHub sessions also carry github_id, the numeric GitHub user id, and amr: ["github"]. The dashboard, the Go API and the Observatory share JWT_SECRET and each verify the session themselves. A session without account_id was issued before accounts existed and counts as signed out everywhere.
Account 1 is the deployment owner. A database that existed before accounts keeps all its history there. It belongs to the password login, to the legacy MCP_AUTH_TOKEN, and to the GitHub user named by OWNER_GITHUB_USER_ID on the API, who claims it on their first GitHub sign-in.
1. Pick the Public URL and Callback URLs
Set APP_URL on the dashboard to the origin users open, for example https://backup.example.com. It is required in production. On a self-hosted machine install.sh sets it from the mode and host names. The dashboard builds its callback URLs from it, and whether its cookies are Secure. When it is unset, both come from the request's Host, X-Forwarded-Host and X-Forwarded-Proto headers. That breaks behind proxies that do not send them, and behind a proxy that passes client-supplied values the client's headers decide them. Leave it unset only for local development.
Set APP_URL on the Go API to the same dashboard origin: the API sends linking workers to <APP_URL>/link.
| Provider | Callback URL | Where it is registered |
|---|---|---|
| GitHub | <APP_URL>/api/auth/github/callback | In the GitHub App or OAuth App (next section) |
| OpenRouter | <APP_URL>/api/auth/openrouter/callback | Nowhere: the dashboard sends it with each authorization request |
| Agent link | <APP_URL>/link?code=ABCD-EFGH | Nowhere: the API prints it to the worker (its own APP_URL) |
For local development the GitHub callback is http://localhost:3000/api/auth/github/callback.
Cookies are marked Secure on every origin except plain-HTTP loopback (http://localhost, http://127.0.0.1, http://[::1]). Serving the dashboard over plain HTTP on any other host (for example http://192.168.1.20:3000) therefore cannot keep a session; use HTTPS or localhost.
2. Create the GitHub OAuth Credentials
Either a GitHub App or a classic OAuth App works. The dashboard needs a client ID and a client secret, uses the GitHub access token only to read the signed-in user's login, id, name and primary verified email, and throws it away.
Option A: GitHub App
- GitHub, Settings > Developer settings > GitHub Apps > New GitHub App.
- Homepage URL:
APP_URL. - Callback URL:
<APP_URL>/api/auth/github/callback. A GitHub App can list several callback URLs, so the production and the localhost callback can share one app. - Leave Request user authorization (OAuth) during installation and Enable Device Flow off, and untick Webhook > Active.
- Permissions: under Account permissions, Email addresses: Read-only lets the account record the user's primary verified email (stored with the account; the product sends no e-mail). Nothing else is needed; without it accounts simply have no email.
- Where can this GitHub App be installed?: Only on this account. The app does not have to be installed for sign-in.
- Create the app, copy the Client ID and generate a client secret.
Option B: OAuth App
- GitHub, Settings > Developer settings > OAuth Apps > New OAuth App.
- Homepage URL:
APP_URL. - Authorization callback URL:
<APP_URL>/api/auth/github/callback. An OAuth App has a single callback URL, so use a second OAuth App for localhost. - Register the app, copy the Client ID and generate a client secret.
The dashboard asks for the user:email scope (an OAuth App needs it to read the email addresses; a GitHub App ignores scopes and uses the permission above) and never offers to create a GitHub account on the way.
3. Decide Who May Sign In (Go API)
Who may have an account is decided by the Go API alone; the dashboard keeps no list of its own. Set these on the API (src/backend/github-backup-api):
| Variable | Default | Purpose |
|---|---|---|
SIGNUP_MODE | allowlist | allowlist: a GitHub user may create an account only when ALLOWED_GITHUB_USERS matches them (or they are the owner). open: anyone with a GitHub account. closed: nobody new. Existing accounts can always sign in unless disabled. |
ALLOWED_GITHUB_USERS | empty | For SIGNUP_MODE=allowlist: comma-separated entries, each a numeric GitHub user id (583231, recommended), a login and its id (octocat:583231, both must match) or a login (octocat, case-insensitive). See Allowlist entries. |
OWNER_GITHUB_USER_ID | unset | Numeric GitHub user id of the deployment owner. On their first GitHub sign-in they claim account 1, with all the history it already holds, instead of getting a new account; they may always sign in. Unset, account 1 is reachable only through the password login, MCP_AUTH_TOKEN and API_REQUIRE_AUTH=false. |
JWT_SECRET | none | The same value as the dashboard's and the Observatory's; the API verifies every session with it. Required (at least 32 characters) while API_REQUIRE_AUTH=true. |
SERVICE_CREDENTIALS | none | The hashes of the calling services' own credentials (ADR 0009). The dashboard's entry (dashboard:<hash>, printed by github-backup-api service-credential new dashboard) authenticates the account lookup during GitHub sign-in; the API's policy lets that credential look up accounts and read only the owner's landing numbers. |
INTERNAL_SECRET | none | Deprecated: the same value as the dashboard's, accepted while the dashboard has no SERVICE_CREDENTIAL. |
APP_URL | unset | The dashboard's public origin, for the agent link URL (section 1). |
A GitHub user the policy turns away sees "This GitHub account is not allowed" with the API's reason and their GitHub user id, which the owner can add to ALLOWED_GITHUB_USERS. A disabled account sees "This account is disabled". Login, name and email are refreshed from GitHub on every sign-in.
Allowlist entries
Prefer numeric user ids. GitHub lets anyone register a login that was freed by a rename, so a login entry (octocat) would let in whoever holds that login today. An id entry (583231) keeps matching the same account after a rename; octocat:583231 additionally requires the current login. Look up an id with gh api users/<login> --jq .id or at https://api.github.com/users/<login>; a refused sign-in also shows the account's id.
Logins and ids can be mixed in one list. A login that consists only of digits must be written as login:id, because a bare number is read as an id. The list only decides who may create an account: removing someone from it does not lock out an account they already have (disable the account for that).
Data is keyed by the account, not by the login, so a GitHub rename keeps the same account and history.
4. Set the Environment Variables
All dashboard variables are read by the dashboard server at request time and never sent to the browser.
Dashboard (src/apps/github-backup-dashboard)
| Variable | Required | Purpose |
|---|---|---|
GITHUB_OAUTH_CLIENT_ID | For GitHub sign-in | Client ID from step 2. When set, the sign-in panels show Sign in with GitHub. |
GITHUB_OAUTH_CLIENT_SECRET | For GitHub sign-in | Client secret from step 2. |
JWT_SECRET | For GitHub sign-in; recommended always | Same value as the API's and the Observatory's. Signs GitHub sessions and verifies every session locally. Without it, each session check (and each gated request) asks the Observatory's GET /auth/me. |
SERVICE_CREDENTIAL | For GitHub sign-in (or INTERNAL_SECRET) | The dashboard's own credential, ghb_svc_ and 43 base64url characters; its hash must be in the API's and the Observatory's SERVICE_CREDENTIALS under the name dashboard first. Used only from the dashboard server to the backends, never for a browser's request: the account lookup during GitHub sign-in and the password login, where it lets the Observatory believe the browser address it reports (X-Client-Address). A malformed value is ignored, and the log names the setting. |
INTERNAL_SECRET | Deprecated | Sent instead of SERVICE_CREDENTIAL while that is unset; the same value as the API's. |
BACKUP_API_URL | Already required | The Go API. The proxy and the server pages call it with the user's session. |
AGENT_API_URL | Already required | The Observatory; the password login, session checks and the OpenRouter exchange call it. |
APP_URL | Required in production | Public origin for callback URLs and the cookies' Secure flag, for example https://dash.example.com. Unset (local development only) means the request's origin. |
PUBLIC_API_URL | No | The Go API as a worker on another machine reaches it, shown in the link instructions on Settings > Agents (github-backup-worker link --control-plane <PUBLIC_API_URL>). Unset, the page shows a placeholder. |
JWT_EXPIRES_MINUTES | No (default 60) | Lifetime of sessions created by GitHub sign-in; the cookie expires with the JWT. Password sessions last as long as the Observatory's token. |
DASHBOARD_REQUIRE_LOGIN | No (default: on when GITHUB_OAUTH_CLIENT_ID or JWT_SECRET is set) | Requires a session for every page and /api/proxy/* (see section 8). false turns the gate off; unrecognised values count as true. |
DASHBOARD_TRUSTED_PROXY | No (default false) | true when a reverse proxy you run sits in front of the dashboard and sets X-Forwarded-For. The dashboard then passes the address the proxy added (the last entry) on: to the Go API as the only X-Forwarded-For entry, and to the Observatory's failed-login limit. Leave it off when browsers reach the dashboard directly: the header would come from the browser, and rotating it would dodge the limits. |
GITHUB_OAUTH_BASE_URL / GITHUB_API_BASE_URL | No | Default https://github.com / https://api.github.com. Only for GitHub Enterprise Server or a local test stub. |
Generate a secret with openssl rand -base64 48 and use the same value on every service. The dashboard no longer reads ALLOWED_GITHUB_USERS; set it on the API.
Observatory (src/services/github-backup-observatory)
| Variable | Purpose |
|---|---|
JWT_SECRET | Same value as the dashboard's and the API's. Sessions need an account_id; the Observatory refuses tokens without one and disabled accounts. |
CHAT_USERNAME / CHAT_PASSWORD | Credentials of the password fallback. Its sessions belong to account 1. |
JWT_EXPIRES_MINUTES | Lifetime of password sessions. |
Settings the Observatory needs for storing per-user OpenRouter keys are described in its own README.
Local Development
With fnox, make dev runs the dashboard, the API and the Observatory on the dev profile of fnox.toml, which already shares JWT_SECRET and INTERNAL_SECRET between them and turns on the password sign-in (dev, password dev-password-local-only). Add the GitHub App's credentials for Sign in with GitHub, and your GitHub user id for the API, to a gitignored fnox.local.toml (SECRETS.md):
[profiles.dev.secrets]
GITHUB_OAUTH_CLIENT_ID = { default = "<client id>", description = "my local GitHub App" }
GITHUB_OAUTH_CLIENT_SECRET = { default = "<client secret>", description = "my local GitHub App" }
OWNER_GITHUB_USER_ID = { default = "<your github user id>", description = "signing in with it claims account 1" }
On the self-hosted machine store them in the selfhost profile (fnox -P selfhost set GITHUB_OAUTH_CLIENT_SECRET, and the same for the client id) and copy them there with make secrets-push-selfhost. Without fnox, put the dashboard values in a gitignored src/apps/github-backup-dashboard/.env.local:
AGENT_API_URL=http://localhost:8000
BACKUP_API_URL=http://localhost:8080
PUBLIC_API_URL=http://localhost:8080
APP_URL=http://localhost:3000
GITHUB_OAUTH_CLIENT_ID=<client id>
GITHUB_OAUTH_CLIENT_SECRET=<client secret>
JWT_SECRET=<same value as the API and the Observatory>
# github-backup-api service-credential new dashboard; its hash goes into the
# API's and the Observatory's SERVICE_CREDENTIALS
SERVICE_CREDENTIAL=<the dashboard's credential>
and on the API OWNER_GITHUB_USER_ID=<your github user id> (plus ALLOWED_GITHUB_USERS for anyone else).
5. Routes and Cookies
| Route | Method | Purpose |
|---|---|---|
/api/auth/github/start?returnTo=/path | GET | Starts GitHub sign-in; returnTo must be a relative path on the dashboard (default /dashboard). |
/api/auth/github/callback | GET | GitHub redirects here; resolves the account at the API, sets the session cookie and returns to returnTo. |
/api/auth/password | POST | Form fields username, password; the Observatory login, done by the server. |
/api/auth/session | GET | {authenticated, username, method, expiresAt, isOwner, providers: {github}}. isOwner (the session is account 1's) only decides what the UI offers, such as the embeddings page. |
/api/auth/logout | POST | Deletes the session cookie (same-origin requests only). |
/api/auth/openrouter/start | GET | Starts "Connect OpenRouter" (requires a session). |
/api/auth/openrouter/callback | GET | OpenRouter redirects here; the Observatory exchanges the code; lands on /settings. |
/api/health | GET | Liveness check, public even with the gate on. |
| Page | Purpose |
|---|---|
/settings | Connections: the signed-in account, Sign out, and the OpenRouter key. |
/settings/tokens | Personal access tokens: create, copy once, revoke (section 6). |
/settings/agents | Linked machines: list, revoke, link instructions (section 7). |
/link?code=ABCD-EFGH | Approve a worker's link code (section 7). |
| Cookie | Path | Lifetime | Content |
|---|---|---|---|
ghb_session | / | The JWT's lifetime | Session JWT |
ghb_github_oauth | /api/auth/github | 10 minutes | OAuth state, PKCE verifier, return path |
ghb_openrouter_pkce | /api/auth/openrouter | 10 minutes | PKCE verifier |
All three are HttpOnly and SameSite=Lax, and Secure except on plain-HTTP loopback origins.
Both proxies (/api/proxy/backup/* to the Go API, /api/proxy/agent/* to the Observatory) send the session JWT as Authorization: Bearer <jwt> and nothing else: never the dashboard's credential or INTERNAL_SECRET, never the browser's own Authorization, X-Service-Credential, X-Internal-Secret or X-Account-Id headers, and only a cookie value shaped like a JWT. Server-rendered pages call the Go API the same way. The Observatory proxy refuses POST/PATCH/DELETE requests that do not come from the dashboard's own pages (Sec-Fetch-Site / Origin check); the account pages change things through Next.js server actions, which accept only same-origin calls.
6. Personal Access Tokens
Settings > Access Tokens (/settings/tokens) creates tokens for scripts and MCP clients:
- Name: where the token is used, up to 100 characters.
- Access: Read only (
read: backups, logs, analytics) or Read and write (read,write: also queue backup runs and record fixes). - Expires: 30 days, 90 days (default), 1 year, or no expiry.
The new token (ghb_pat_…) is shown once, with a copy button; the dashboard does not keep it and the API stores only its hash, so a lost token is revoked and replaced. The list shows each token's name, prefix and last four characters, access, creation, last use and expiry. Revoke (with a confirmation) stops it at once. An account has at most 20 active tokens.
Send it as Authorization: Bearer ghb_pat_… to the Go API (/api/*) and the MCP server. The Observatory (the AI chat) does not accept personal tokens.
The dashboard creates, lists and revokes tokens from its server with the user's session (GET/POST /api/tokens, DELETE /api/tokens/:id on the API); the browser only ever sees the new token once.
7. Agents: Linking a Machine
A worker on any machine can back up for an account without a database connection: it reports runs to the API with an agent token (ghb_agt_…, scope agent, no expiry).
- Install the worker on that machine (
make setup). - Run
github-backup-worker link --control-plane <API URL>(the API's public URL; Settings > Agents shows it whenPUBLIC_API_URLis set). It prints a code such asBCDF-GHJKand opens<APP_URL>/link?code=BCDF-GHJK. - On that page, signed in as the account the machine should back up for, check the code. The page looks it up first and shows the machine that asks (agent name, host, worker version, when the code expires); click Approve only if that is the machine you just ran the command on. The worker picks up its token within a few seconds and stores it. An unknown, expired or already used code is refused with a message to start the link again.
Approve only a code you started yourself: whoever started it gets an agent token for your account. Codes expire after 10 minutes and work once. Settings > Agents (/settings/agents) lists the linked machines (name, host, version, when linked, last seen) and Revoke stops a machine's token at once. See CLI_AUTH_SETUP.md for the worker side.
8. Login Gate
The Go API checks every request itself: the dashboard forwards the user's session and never adds its own credential to a browser's request, so a visitor without a session gets no account data from the API (with API_REQUIRE_AUTH=true). The gate decides whether signed-out visitors see the app's pages at all. It is on as soon as a sign-in method is configured (GITHUB_OAUTH_CLIENT_ID or JWT_SECRET on the dashboard; Compose always sets JWT_SECRET), and DASHBOARD_REQUIRE_LOGIN=true turns it on regardless. While it is on:
- Pages redirect signed-out visitors to
/signin?returnTo=<page>, so/link?code=…comes back with its code after sign-in. /api/proxy/*answers401JSON (AUTH_REQUIRED), or503when the Observatory cannot confirm a session.- The landing page
/and the other public pages,/api/auth/*,/api/health,/api/waitlist,/signin, what crawlers read (/robots.txt,/sitemap.xml,/llms.txt, the Google verification file) and static assets (/_next/static/*,/_next/image, the favicon and app icons, and the files inpublic/:/og.jpg) stay public (/og.pngredirects to/og.jpginnext.config.ts, which runs before the gate); a path that merely ends in a file extension, such as/api/proxy/backup/api/backups/5.png, is still gated. The overview at/dashboardand every other page are gated.
The landing page shows no live numbers: it is a static page with one dated sample run and other recorded data (src/content/landing.ts). LANDING_PUBLIC_STATS was removed on 2026-11-05 and is ignored if still set.
Make sure someone can sign in before deploying: set CHAT_USERNAME / CHAT_PASSWORD on the Observatory or the GitHub settings above, or every gated page ends on /signin. With DASHBOARD_REQUIRE_LOGIN=false the pages render for everyone, but an API with API_REQUIRE_AUTH=true returns no data without a session, so the pages stay empty until the visitor signs in; with API_REQUIRE_AUTH=false (local development only) a request without a session reads the owner's data.
Set JWT_SECRET on the dashboard when the gate is on; otherwise every gated request costs one call to the Observatory. Point container health checks at /api/health rather than a page. After sign-in with no valid returnTo, users land on /dashboard.
9. Troubleshooting
| Symptom | Cause |
|---|---|
| "GitHub sign-in is not configured" (503) | GITHUB_OAUTH_CLIENT_ID, GITHUB_OAUTH_CLIENT_SECRET, JWT_SECRET or SERVICE_CREDENTIAL (or INTERNAL_SECRET) is missing on the dashboard; the page names the missing ones. |
| "This GitHub account is not allowed" (403) | The API's signup policy refused a new account: SIGNUP_MODE=closed, or allowlist without a matching ALLOWED_GITHUB_USERS entry (the page shows the user id to add). |
| "This account is disabled" (403) | The account exists but is disabled at the API. |
| "The backup API is unreachable" (503) | GitHub confirmed the user but the API did not answer the account lookup (down, timed out or a 5xx). Try again; check BACKUP_API_URL. |
| "Sign-in is not set up correctly" (502) | The API refused the account lookup or answered without an account: the API's SERVICE_CREDENTIALS has no dashboard entry for the dashboard's SERVICE_CREDENTIAL (401, or 403 from the policy), INTERNAL_SECRET differs between the dashboard and the API, or the API predates accounts. The password login says the same when the Observatory refuses the dashboard's credential, instead of "wrong password". |
GitHub reports that the redirect_uri is not associated with the application | The registered callback URL differs from <APP_URL>/api/auth/github/callback, or APP_URL is unset behind a proxy. |
| "Sign-in could not be verified" (400) | The sign-in took longer than 10 minutes, was started in another browser, or cookies are blocked. |
| "The Observatory issued a session this dashboard cannot verify" | JWT_SECRET differs between the services, the Observatory issues tokens without iss/aud, or an Observatory that predates accounts issues sessions without account_id. |
| Everyone is signed out after the upgrade to accounts | Expected once: sessions without account_id are no longer valid. Sign in again. |
| Signed in, but pages are empty or settings say "The backup API did not accept your session" | The API cannot verify the session: JWT_SECRET missing or different on the API. |
| Signed in, but the AI pages show "The AI assistant did not accept your session" | The Observatory rejects a JWT the dashboard accepts: a different JWT_SECRET, a disabled account, or an Observatory build that predates accounts. You stay signed in; a session that really expired signs you out with "Your session expired". |
| The link page says the code is unknown, expired or used | Codes last 10 minutes and work once; run github-backup-worker link again. |
| Sign-in works on localhost but not on a LAN address | Session cookies are Secure; use HTTPS. |
10. Migrating
To accounts (multi-user)
- Set
OWNER_GITHUB_USER_IDon the API to your own GitHub user id before you sign in with GitHub, so you claim account 1 and keep the existing history. MoveALLOWED_GITHUB_USERSto the API (it is the API's signup allowlist now; the dashboard ignores it) and chooseSIGNUP_MODE. - Set
JWT_SECRETon the API (the same value as the dashboard and the Observatory) and give the dashboardSERVICE_CREDENTIAL(or keepINTERNAL_SECRET): GitHub sign-in needs it for the account lookup. - Every user signs in once more: existing sessions have no
account_id. - The landing page's numbers are now opt-in (
LANDING_PUBLIC_STATS=true), also without the gate. - Scripts that called the API with
INTERNAL_SECRETact for an account only withX-Account-Id; give them a personal access token instead (section 6).
From the shared-password login
- Earlier builds kept the JWT in
localStorage(agent_token,agent_username). The dashboard deletes those keys on the first page load, so every existing user is signed out once and signs in again. /api/proxy/agent/auth/loginand/api/proxy/agent/auth/meare no longer forwarded; sign-in goes through/api/auth/*.- Earlier builds showed every page without a sign-in. Once
JWT_SECRETorGITHUB_OAUTH_CLIENT_IDis set on the dashboard, every page now needs a session (section 8); a deployment that must stay open setsDASHBOARD_REQUIRE_LOGIN=false.