Repository navigation
Phase 1: Backend device authorization flow - #1287
Merged
neuromechanist merged 12 commits intoSep 7, 2026
Merged
neuromechanist merged 12 commits into
neuromechanist merged 12 commits into
Conversation
📦 Package PreviewYour package is ready to test! bun install -g nemar-cli@PR1287Version: 🤖 Updated on each push. |
neuromechanist
merged commit Sep 7, 2026
5a348bf
into
feature/issue-1272-epic-orcid-cli-signin
12 checks passed
This was referenced Sep 7, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Backend half of ORCID-first CLI sign-in: the device authorization grant (RFC 8628), the pattern
gh auth loginuses, sonemar auth logincan obtain its API key through a browser ORCID sign-in on any device without a redirect reaching the terminal.New: migration 0081
device_codes;POST /auth/device/startandPOST /auth/device/tokenfor the CLI;GET /auth/device/lookup,POST /auth/device/confirm,POST /auth/device/denyfor the website page (phase 2) behind the existing web session; named per-machine keys withGET/POST /auth/keysandDELETE /auth/keys/:id(currenton the bearer path) for the paste-key fallback and phase 3's logout; the shared vocabulary inshared/contract/device-auth.ts; ADR 0047.Design points the review should check (ADR 0047): the key is minted only when the CLI collects it, never at confirm, inside one
db.batch()gated onEXISTSrather thanlast_insert_rowid(); the polling secret is stored hashed; every timestamp is written and compared in SQL; confirm grants a 120 s collection grace;/auth/device/tokenis deliberately outsideAUTH_PATHSand carries its own per-row 5 s floor;identity_conflictrefuses new sign-ins only;account_revokedis unreachable at confirm because revoked accounts hold no web session.Closes #1281
Part of epic #1272
Test plan
backend/test/device-codes-migration.test.tsruns the exported SQL against bun:sqlite: PK, UNIQUE, CHECKs, SQL-side expiry format, confirm-once with grace, poll floor, stamp-once, prune, the mint pair for verified/pending/revoked/flagged/at-cap accounts, cascade and SET NULLbackend/test/device-auth-routes.test.ts(41 cases at the HTTP entry points, ORCID stand-in viaBun.serve): start, poll states, expiry audited once, lookup, confirm, deny, mint after confirm, account changes between confirm and collect, wrong account, prune, and a brand-new ORCID iD going pending, verify, confirm, tokenbackend/test/api-keys-routes.test.ts(12 cases): list, current marker, cap, revoke one and keep the others,currenton both credential pathsbackend/test/rate-limit-buckets.test.ts: the five strict paths and the deliberate exclusion oftokentest/contract-device-auth.unit.test.ts: alphabet, format/normalize, every code has a two-sentence messagebun run lint,bun run typecheck,bun run migrations:d1-check(real local D1 replay) cleantest/auth-device-flow.test.ts(live tier) skips loudly until the routes reach the dev worker, which deploys only fromdev; runs once the epic lands or the branch is deployed by handFollow-up filed: #1286 (pre-existing ISO-versus-SQL timestamp comparisons in
auth_codes,web_sessions,orcid_link_intents).