Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/login-hooks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'seamless-auth-api': minor
---

Add `post_login` and `pre_token` login hooks (ADR 0005, #419).

- Admin API under `/admin/login-hooks/:trigger`: create or replace, read, delete, rotate the signing secret (24 hour overlap), send a test call, and list invocations (kept 30 days). Every write takes step-up and is audited.
- Calls are signed like webhooks, with the invocation id as `webhook-id`, and carry the user, method, organization and request IP and user agent. They never carry a token, code or secret. One attempt, 2 seconds by default and 5 at most.
- `post_login` runs once the factor is proven and before the session exists, and may deny. `pre_token` runs for a new session and on organization switch, and may add claims or deny. Its claims are kept on the session, copied on refresh and to an exchanged session, and dropped when the user leaves the organization they were decided for. Reserved claim names are stripped and audited; the rest are held to 1 KiB.
- Break-glass administrators and recovery sessions never call a hook.
- Contract change: sign-in completion routes and `POST /organizations/:id/switch` can now answer 403 `{ "error": "login_denied", "message"?: "<the hook's userMessage>" }` when a hook denies, and 503 `{ "error": "login_hook_unavailable" }` when a hook set to fail closed times out, answers other than 2xx, or returns a body that does not parse or fit the budget. The hook's `reason` is audited and never returned.
- Access tokens can carry `pre_token` claims beside the existing ones. They can never replace a reserved claim.
- New audit events `login_hook_success`, `login_hook_denied`, `login_hook_failed`, `login_hook_claims_stripped`, `admin_login_hook_set`, `admin_login_hook_deleted` and `admin_login_hook_secret_rotated`.
- `CALLOUT_SECRET_ENCRYPTION_KEY` is now required in production once a login hook exists, as it is for webhooks.
7 changes: 7 additions & 0 deletions adapter-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
{ "method": "GET", "path": "/admin/credential-count", "credential": "access" },
{ "method": "GET", "path": "/admin/enrollment", "credential": "access" },
{ "method": "POST", "path": "/admin/enrollment/invites", "credential": "access" },
{ "method": "GET", "path": "/admin/login-hooks", "credential": "access" },
{ "method": "DELETE", "path": "/admin/login-hooks/{trigger}", "credential": "access" },
{ "method": "GET", "path": "/admin/login-hooks/{trigger}", "credential": "access" },
{ "method": "PUT", "path": "/admin/login-hooks/{trigger}", "credential": "access" },
{ "method": "GET", "path": "/admin/login-hooks/{trigger}/invocations", "credential": "access" },
{ "method": "POST", "path": "/admin/login-hooks/{trigger}/secret", "credential": "access" },
{ "method": "POST", "path": "/admin/login-hooks/{trigger}/test", "credential": "access" },
{ "method": "POST", "path": "/admin/organization-roles", "credential": "access" },
{ "method": "DELETE", "path": "/admin/organization-roles/{roleName}", "credential": "access" },
{ "method": "PATCH", "path": "/admin/organization-roles/{roleName}", "credential": "access" },
Expand Down
10 changes: 10 additions & 0 deletions docs/adr/0005-extensibility-callouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ They must be read back to sign, so they cannot be hashed. They are AES-256-GCM e
- Deleting a passkey (`DELETE /users/credentials`) wrote no audit event. It now writes `credentials_deleted` naming the passkey. Reproducing test first.
- Passkey registration and account registration both write `registration_success`. The passkey path now names the credential in metadata, which is how the catalog tells them apart.
- `organization_member_updated` recorded only what was added and removed. It now records the roles after the change too, which the webhook carries.
- Login hooks (#419):
- A denied sign-in answers 403 `login_denied`, with the hook's `userMessage` as `message`. A hook that fails closed answers 503 `login_hook_unavailable`, since the user did nothing wrong and can retry.
- `issueSessionAndRespond` now answers the refusal itself and resolves false, because most sign-in controllers turn a thrown error into a 500. Callers stop there, so a refused sign-in records no last login.
- Hooks run before the concurrent session limit, so a refused sign-in cannot evict a session the user already had.
- A `pre_token` claim with a name outside the claim alphabet, or nested past depth 3, fails the hook rather than being dropped. Only reserved names are stripped. Claims over the budget fail as `too_large`.
- The session that completes a new account's address verification calls hooks like any other sign-in. It is a full session, not a recovery one.
- A session exchange copies the parent's `pre_token` claims to the child, for both grants, since the claims describe the user rather than the factor.
- When a mint finds the user has left the session's organization, the session's hook claims are cleared with the organization, since the hook decided them for it.
- `client` in the call is always null for now: no first-party sign-in knows which OpenID Provider client it is for. The provider can fill it in seamless-auth-oidc-provider#47.
- A test call sends a placeholder user and no request details, and is not recorded as an invocation.

## Consequences

Expand Down
Loading
Loading