Repository navigation
Description
Parent
Auth: Clerk, companies and machine tokens on tier 0, spec §6, §8 and §9.
What to build
The server side of patchy login, and the page where a person sees their machines. A POST starts a device login and hands back a code and a confirm URL; the confirm page behind the session shows the code, names the company and the person, takes a machine name, and confirms or denies; the poll that finds a confirmed login mints the machine token exactly once and deletes the row. Your machines lists live tokens with revoke one, revoke all and sign out. Drivable with curl and a browser before the CLI ticket lands.
Do
DeviceLoginsin Auth:start(delete rows past expiry, then apendingrow with the user code fromBCDFGHJKLMNPQRSTVWXZasXXXX-XXXX, the device code's hash, the hint, the old key's id, ten minutes),lookupby user code for the page,confirm(user, name,confirmed) anddeny,poll(pending, slow down, or the one-time mint: mint the token with 90-dayexpires_at, revoke the old key when it is the same user's, delete the row, all in one transaction, return the plaintext from memory; expired, denied and unknown as 410 answers, each deleting its row).- Wire:
POST /api/login/deviceandPOST /api/login/device/tokenexactly as spec §6, admitted by the guard with no credential (the mint's old place), start limited per address (PATCHY_DEVICE_LOGIN_RATE_LIMIT_PER_MINUTE, default 5), the poll limited per device code at the interval. Re-renderdocs/API.md; its preamble names these two as the unauthenticated routes. - Pages (Auth, behind
RequireSession):GET /login/device?code=…andPOST /login/devicewith the copy and every reverse state from patchy login end to end, variant A, except two lines the poll-mints decision changes (spec §8): the re-login line reads Replaces the key named<name>, which stops working once your terminal finishes logging in, and the confirmed state reads Confirmed. Your terminal finishes logging in on its own within a few seconds. You can close this tab. (confirmed, denied, expired 410, already answered 410, unknown 404, a blank or over-long name 422, the press Confirm again notice when a signed-outPOSTanswered 303 to theGETwith the code from the body); a bare/login/deviceas the message page. The confirm page's lookup is limited per user.GET /machines(live tokens: name, created, last used, expires),POST /machines/:id/revoke,POST /machines/revoke-all,POST /logout(revoke the Clerk session, clear every Clerk cookie with the setter'sDomainandPath, 303 to/login; needs a Clerk session and nothing else, so the sign-out controls on create-or-join and the deactivated page from the sign-in ticket now work end to end)./login's default return becomes/machines. - Analytics:
token.mintedon the poll's mint with the user as principal and whether an old key was replaced. - ADR: Every bearer is somebody: the machine token: the one Patchy credential, user-owned, one per machine, 90 days or 30 idle, minted at the poll and never stored in plaintext, revoked only by its user (one, all,
logout) or by deactivation, no bootstrap or operator credential, the confirm-not-type protocol and why. - Tests: the state machine end to end on the test clock (start, confirm, poll mints once and the row leaves; deny; expiry; a second poll answers unknown; slow down; the old key revoked only when it is the same user's; an abandoned confirm mints nothing; two concurrent polls of one confirmed login mint exactly one token and the loser answers unknown; a user deactivated between confirm and poll gets no token); the pages in memory with a keypair session, every reverse state's status and copy; sign-out leaves no Clerk cookie in the jar; the guard admits the two routes and nothing else without a bearer.
- Glossary: Auth's Device login (the URL carries the code; confirmed, never typed; minted at the poll) and Your machines (sign-out lives here);
docs/product.md§ Machines and tokens' CI sentence to the future tense.
Surfaces
The wire contract; served pages (ui-consistency on the confirm page and Your machines); vocabulary and product shape; reverse states (revoke one and all; deny beside confirm).
Done when
- On a
pnpm devinstance:curl -X POST /api/login/devicereturns a code and URL; the URL in a signed-in browser shows the code, the company and the person; Confirm then acurlpoll returns the token once and a second poll returns 410unknown;whoamiwith that token prints the machine's name;/machineslists it and revoke makes the token a 401. - Sign-out on
/machineslands on/loginand the next/companyvisit is the door. -
pnpm test,pnpm typecheck,pnpm lintand the packed e2e pass; the ADR is in the PR.
Decisions implemented
Device login: the protocol, and the machine token's columns with its addenda; patchy login end to end; Device login: the protocol facts; Data model (minting at the poll); spec §6, §8, §9, §12. The prototype branch prototype/patchy-login has the routes, the page in three variants and the reverse states; copy the shape, not the files.
Activity
feat(auth): add device login and Your machines
feat(auth): add device login and Your machines