DEVELOPER DOCS

REST API

CLI Authorization (device flow)

On this page

How evigauge login obtains an API key without the key ever being typed, pasted, or shown in a browser.

The CLI runs an OAuth 2.0 device authorization flow. It displays a short user code and opens the dashboard at /cli/authorize; the signed-in operator confirms that code and picks a workspace; the CLI, which has been polling throughout, mints and stores the key itself.

code
   CLI                          Browser (dashboard)            Backend
    │  start device flow ─────────────────────────────────────────▶
    │  ◀──────────────── user_code + verification URL
    │  show code, open browser ──▶ /cli/authorize?user_code=…
    │                              GET  /v1/cli/workspaces ──────▶
    │                              ◀──── workspaces the user may approve
    │                              POST /v1/cli/device/approve ──▶
    │  poll ──────────────────────────────────────────────────────▶
    │  ◀──────────────── api key (minted here, not in the browser)

The dashboard never sees the key. Approving is all that happens in the browser, which is why neither endpoint below carries a secret in either direction. The key exists only in the CLI's own store.

Not under /v1/observ — the automatic ?project= rule does not apply, and neither takes an org or workspace slug in the path.


List approvable workspaces

HTTP
GET /v1/cli/workspaces

Every workspace the signed-in user may authorize a CLI login for. The server computes this with the same rule approve enforces, so the list is "shown = will succeed".

Auth: JWT (a signed-in browser session) · Role: any authenticated user

Response 200 — not schema-modelled

JSON
{
  "workspaces": [
    {
      "workspace_id": "8f21c7a0-4d3b-11f0-9cd6-0242ac120002",
      "slug": "production",
      "name": "Production",
      "org_id": "3c10ab54-2e77-4a1d-9a02-6b5f0d8e1c44",
      "role": "admin"
    }
  ]
}
FieldNotes
workspace_idUUID — this is what approve takes, not the slug
roleWhy they are eligible: owner, admin or dev. Viewers never appear

Do not re-implement the eligibility rule client-side. Filtering the list again by role can only ever drift from what the server will accept, and the drift shows up as an option that fails on approve.


Approve a pending login

HTTP
POST /v1/cli/device/approve

Marks a pending device request as approved for one workspace. The CLI's next poll is what actually mints the key.

Auth: JWT (a signed-in browser session) · Role: owner, admin or dev on the target workspace

Request body

NameTypeRequiredDescription
user_codestring✅Exactly as shown in the terminal
workspace_idstring✅UUID from GET /v1/cli/workspaces
project_idstring➖Recorded for display only — not an access boundary. Omit entirely to fall back to the workspace default; do not send ""

Response 200 — not schema-modelled

JSON
{ "approved": true }

Errors

StatusMeaningWhat the user should do
400The code is unknown, already used, or expiredNothing is wrong with their account — start a new evigauge login
403Not permitted on that workspaceShould be unreachable if the picker was populated from /v1/cli/workspaces; if it fires, the list and the check have drifted

Keep these two distinct all the way to the user. They need different things: one is "try again", the other is "you cannot do this here", and collapsing them into a generic failure sends people to support for a code that simply timed out.

Confirm the code, never auto-approve. The operator must be shown the user_code and asked to match it against their own terminal. A page that approves on load is a working phishing vector: an attacker starts a device flow, sends the victim the link, and receives a key scoped to the victim's workspace. The confirmation step is the whole defence.


Example — approving from a custom dashboard

TypeScript

TypeScript
// 1. Offer only what the server says will succeed.
const { workspaces } = await evigauge.get("/v1/cli/workspaces");
if (workspaces.length === 0) throw new Error("No workspace you can authorize.");

// 2. The operator picks one AND confirms the code matches their terminal.
const workspace_id = workspaces[0].workspace_id;   // UUID, not slug
const user_code = "BQDJ-XKFP";                     // typed/confirmed by the human

// 3. Approve. The key is minted by the CLI's poll, never returned here.
try {
  const { approved } = await evigauge.post("/v1/cli/device/approve", {
    user_code, workspace_id,
  });
  if (approved) console.log("Approved — return to your terminal.");
} catch (e: any) {
  if (e.status === 400) console.error("Code invalid or expired — run `evigauge login` again.");
  else if (e.status === 403) console.error("That workspace rejected the request.");
  else throw e;
}