feat: two-factor sign-in, required for sensitive permissions
Better Auth's twoFactor plugin: an authenticator app (TOTP) with 10 backup codes. Turning it on, making new backup codes and turning it off are on the account page, and signing in asks for a code once it's on. Sensitive permissions (product:remove, person:ban, person:role, settings:edit, catalog:suspend, ...) answer 403 two_factor_required without it, API tokens included; the console reminds people who need it. Better Auth's own admin endpoints are closed (404). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
69c55a72fb
commit
d5bc792190
28 files changed
+4365
-62
No files matched your search
+2
-1
@@ -20,7 +20,8 @@ is. Codes: `invalid`, `signed_out`, `forbidden`, `not_found`, `no_such_imvu_acco
|
||||
| | |
|
||||
| --- | --- |
|
||||
| `POST /api/auth/sign-up/email` | `{email, password, name, username}`. Usernames 3-32 of `A-Za-z0-9_`; passwords 10-256 characters. The first account is an admin. With registration closed, the others wait for approval (`approved: false`): every route but `/me` answers 403 `awaiting_approval`, and the rest of the hub treats them as signed out. |
|
||||
| `POST /api/auth/sign-in/username` | `{username, password}` |
|
||||
| `POST /api/auth/sign-in/username` | `{username, password}`. With two-factor sign-in on, it answers `{twoFactorRedirect: true, twoFactorMethods: ["totp"]}` and no session: then `POST /api/auth/two-factor/verify-totp` `{code}` (from the app) or `/verify-backup-code` `{code}` signs in. |
|
||||
| `POST /api/auth/two-factor/enable` | `{password}` → `{totpURI, backupCodes}`; on once `POST /api/auth/two-factor/verify-totp` `{code}` confirms it. `/two-factor/disable` and `/two-factor/generate-backup-codes` take `{password}`. Sensitive permissions need it on (docs/console.md). `/api/auth/admin/*` answers 404. |
|
||||
| `POST /api/auth/sign-out` | |
|
||||
| `GET /api/v1/me` | `{person}` (`approved` false while waiting), with `picture`: the avatar picture of their first linked IMVU account (from IMVU, kept an hour), or `null`, `console`: whether the console is for them, and `unread`: their unread notifications |
|
||||
| `GET /api/v1/hub` | (anyone) `{registration}`: `open` or `closed` |
|
||||
|
||||
+12
-1
@@ -75,7 +75,18 @@ while viewing.
|
||||
Anyone holding a sensitive permission must have two-factor sign-in on (Better Auth's `twoFactor` plugin, TOTP with
|
||||
backup codes): `product:remove`, `person:ban`, `person:role`, `audit:read-sensitive`, `catalog:transfer`,
|
||||
`catalog:suspend`, `import:grant-on-behalf`, `settings:edit`. Without it, those actions answer 403
|
||||
`two_factor_required` and the console asks them to set it up. Giving someone such a role reminds them.
|
||||
`two_factor_required` (with `permission`) and the console asks them to set it up. Giving someone such a role
|
||||
reminds them.
|
||||
|
||||
Built (2026-11-05): `permissions.ts` `sensitive`; `require` throws `TwoFactorRequired` after the permission check,
|
||||
so API tokens are covered too (their owner needs it on). Turning it on is on the account page: the password, then a
|
||||
QR code (and the key as text) for an authenticator app, 10 backup codes, and a code from the app to confirm (Better
|
||||
Auth's `/two-factor/enable` and `/verify-totp`). Signing in then asks for a code from the app or a backup code (each
|
||||
works once). The account page can make new backup codes or turn it off (the password each time). `GET /account`
|
||||
has `twoFactor: {enabled, neededFor}` (the sensitive permissions the person holds anywhere), `GET /console` has
|
||||
`twoFactorNeededFor` (empty once it's on; the console shows a reminder), and people in the console show
|
||||
`twoFactor`. Better Auth's own admin endpoints (`/api/auth/admin/*`) answer 404: bans and roles go through the hub's
|
||||
routes, with the checks and the audit log. No "trust this browser": every sign-in asks.
|
||||
|
||||
## The console
|
||||
|
||||
|
||||
+2
-2
@@ -478,8 +478,8 @@ Phases for products, catalogs and imports (products.md, console.md, imports.md):
|
||||
(to look into with the importer spike).
|
||||
3. Cases (reports, appeals, reviews), file blocks and the catalogs' changes feed; notifications; API tokens;
|
||||
two-factor sign-in for sensitive permissions. Cases and notifications **done** (2026-11-05), without email, canned
|
||||
reasons, moderator notes or second approval. File blocks and API tokens **done** (2026-11-05); two-factor
|
||||
sign-in next.
|
||||
reasons, moderator notes or second approval. File blocks, API tokens and two-factor sign-in **done**
|
||||
(2026-11-05); auditing turning two-factor on and off, and "trust this browser", later.
|
||||
4. Imports: grants, recorded grants, requests, unclaimed creators, the job queue, `t5de-importer` (after its spike).
|
||||
5. Charts and stats; mirroring between catalogs.
|
||||
|
||||
|
||||
Reference in new issue
Block a user