diff --git a/docs/architecture.md b/docs/architecture.md index 12fbd4f..f50396f 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -336,6 +336,18 @@ access token (`revoked`) or no refresh is due (`current`; due means a known expiry within 5 minutes, a stored refresh token, and a runtime that refreshes). It never decides that a refresh happens. +### One writer for `linked_identities` moves + +An identity belongs to the account that holds it. `upsertLinkedIdentity` writes +the holder's own row (`ON CONFLICT (provider, provider_user_id) DO UPDATE ... +WHERE linked_identities.account_id = EXCLUDED.account_id`; it never sets +`account_id`) and throws `IdentityHeldElsewhereError` when another account holds +the identity. `unlinkLinkedIdentity` is the only delete: one transaction locks +the account row, refuses the account's last identity, and deletes the row only +for the account that holds it. The store role therefore holds DELETE on +`linked_identities`, checked at startup. The HTTP side (`/v1/me/identities`) is +in `service-contract.md`; an unlink needs a step-up proof inside 600 seconds. + ### Three nested guards 1. **Single flight, per process.** `refreshesInFlight` is keyed by store, then diff --git a/docs/service-contract.md b/docs/service-contract.md index 0469186..b818715 100644 --- a/docs/service-contract.md +++ b/docs/service-contract.md @@ -548,6 +548,80 @@ Important behavior: - the endpoint is not a provider OAuth start path and should not produce a provider authorization URL +### `GET /v1/me/identities` + +The identities the signed-in account holds, for a member's own view. + +Authentication: a live Heimdall access token for any app as +`Authorization: Bearer` (the same check as `/v1/me/grants`). `401 +sign_in_required` otherwise. The answer is `Cache-Control: no-store`. + +```json +{ + "accountId": "uuid", + "identities": [ + { + "id": "uuid", + "provider": "twitch", + "providerUserId": "12345", + "username": "name", + "displayName": "Name", + "linkedAt": "2026-11-13T12:00:00.000Z", + "scopes": ["user:read:email"] + } + ] +} +``` + +`username` and `displayName` are present when the provider gave them. The +answer never carries a token column, the stored provider profile or the +account's email. + +### `POST /v1/me/identities/{identityId}/unlink` + +Takes one identity off the signed-in account. It is the only way a linked +identity is deleted, and it never takes the account's last one. + +Authentication: a live Heimdall access token for any app, and fresh proof. The +body is empty or `null`. + +- `401 sign_in_required`: no live bearer. +- `403 step_up_required`: the access token carries no `step_up_at` claim, or it + is in the future, or it is older than 600 seconds + (`STEP_UP_PROOF_TTL_SECONDS`, `src/claims.ts`). The remedy is a `sign_in` + start with `stepUp: true` (see step-up above) through an identity on the + account whose provider has re-authentication parameters, today twitch, + youtube and google, then the access token that sign-in returns. +- `404 identity_not_found`: no such identity, or one that belongs to another + account. The two are not distinguishable. +- `409 last_identity`: the account holds no other identity. +- `200`: `{"unlinked": {"id", "provider", "providerUserId"}, "identities": [...]}` + with the remaining list in the shape above. + +`step_up_at` (epoch seconds) is set on the access claim only when the callback's +signed state has `step_up` true and mode `sign_in`. A refresh never carries it: +tokens a refresh issues cannot unlink, so proof is renewed only by a new step-up +sign-in. The unlink writes the audit event `identity_unlinked` (provider and +identity id only). When the account then holds no identity of that provider, the +revocation receipts for its live grants of that provider are written, as the +grants revoke route writes them. + +Limits that stay: + +- Access tokens issued before the unlink keep the unlinked identity in their + `identities` claim and its facts until they expire (`sessionTtlSeconds`). +- Discord and Patreon identities cannot give proof (no re-authentication + parameter); an account holding only those cannot unlink. +- A stolen access token minted by a step-up sign-in can unlink more than one + identity during its 600 second window. +- A sign-in through a provider whose identity is no longer linked mints a new + account. + +A link no longer moves an identity: `upsertLinkedIdentity` refuses an identity +another account holds (`links/confirm` answers `409 identity_linked_elsewhere`, +the callback `link_initiator_mismatch`). An unlinked identity belongs to no +account and can be linked by any account through the normal link flow. + ### `POST /v1/apps/{appSlug}/managed-credentials/resolve` Purpose: diff --git a/state/evidence.jsonl b/state/evidence.jsonl index f7fa724..5fd99b4 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -38,3 +38,4 @@ {"ts": "2026-10-19T15:56:24+00:00", "type": "design", "status": "accepted", "note": "Refresh is now one locked primitive for every provider (replaces unserialized refreshLinkedIdentityCredentialIfNeeded); Joystick is managed-only (Heimdall-held credential, no viewer sign-in until joystick:follow_up:joystick-viewer-signin-public-bot). Merged in PR #1, live at d51fa6b; campaign joystick:campaign:self.", "branch": "eureka/joystick-h1"} {"ts": "2026-10-19T16:03:16+00:00", "type": "verification", "status": "accepted", "note": "Live d51fa6b (H1) verified by a real human sign-in: the operator's StreamPixels Twitch sign-in through Heimdall start/callback, 2026-10-19 ('Twitch auth worked fine'); a streampixels session was created 16:02:33Z, after the 15:51Z switch. Joystick consent round trip still open: joystick:follow_up:h1-joystick-consent-round-trip."} {"ts": "2026-11-12T23:10:15+00:00", "type": "design", "status": "accepted", "note": "Changelog 2026-11-12: sign_in start accepts stepUp (app-authenticated, sign_in only, off by default); signed state carries step_up; launch adds Twitch force_verify=true, YouTube prompt='login consent', Google prompt=login; any other provider is 400 step_up_not_supported; completion reports stepUpRequested. Not deployed. For joystick:follow_up:chat-s7055-7056 (StreamPixels link hardening, second factor via fresh sign-in)."} +{"ts": "2026-11-13T19:10:00+00:00", "type": "design", "status": "accepted", "note": "Changelog 2026-11-13: GET /v1/me/identities lists an account's identities (no credentials, profile or email); POST /v1/me/identities/:id/unlink deletes one with a step-up proof (access claim step_up_at, 600 s, never carried by refresh), refuses the last identity (409), writes revocation receipts when the provider's last identity goes. upsertLinkedIdentity no longer moves an identity between accounts (IdentityHeldElsewhereError; links/confirm 409 identity_linked_elsewhere, callback link_initiator_mismatch). The store role needs DELETE on linked_identities (startup refuses without it): owner-role GRANT at deploy."}