Skip to content

feat(auth): device login on the server, the confirm page and Your machines #141

Closed

Description

@allisonmahmood

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

  • DeviceLogins in Auth: start (delete rows past expiry, then a pending row with the user code from BCDFGHJKLMNPQRSTVWXZ as XXXX-XXXX, the device code's hash, the hint, the old key's id, ten minutes), lookup by user code for the page, confirm (user, name, confirmed) and deny, poll (pending, slow down, or the one-time mint: mint the token with 90-day expires_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/device and POST /api/login/device/token exactly 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-render docs/API.md; its preamble names these two as the unauthenticated routes.
  • Pages (Auth, behind RequireSession): GET /login/device?code=… and POST /login/device with 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-out POST answered 303 to the GET with the code from the body); a bare /login/device as 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's Domain and Path, 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.minted on 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 dev instance: curl -X POST /api/login/device returns a code and URL; the URL in a signed-in browser shows the code, the company and the person; Confirm then a curl poll returns the token once and a second poll returns 410 unknown; whoami with that token prints the machine's name; /machines lists it and revoke makes the token a 401.
  • Sign-out on /machines lands on /login and the next /company visit is the door.
  • pnpm test, pnpm typecheck, pnpm lint and 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.

Blocked by

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:docsarea:serverready-for-agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions