@atol-sh/js 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,843 @@
1
+ # Response-vault browser authorization protocol v1
2
+
3
+ Response-vault v1 is a public Atol browser authorization profile. It combines
4
+ an exact JSON pushed request, parameter-free navigation, a same-origin
5
+ one-use relay, DPoP-bound issuance, capability settlement, and durable state
6
+ machines. Authorization responses stay out of navigation URLs, form posts,
7
+ `postMessage`, and browser-persisted bearer-token storage.
8
+
9
+ The words MUST, MUST NOT, SHOULD, and MAY describe requirements for an
10
+ interoperable v1 implementation.
11
+
12
+ ## Enabling the profile
13
+
14
+ The public SDK enables the profile with `responseVault: true`:
15
+
16
+ ```ts
17
+ const auth = createAtolBrowserAuth({
18
+ issuer: 'https://id.example.com',
19
+ clientId: 'example-spa',
20
+ audience: 'https://api.example.com',
21
+ scopes: 'openid profile email',
22
+ redirectUri: 'https://app.example.com/oidc/complete',
23
+ postLogoutRedirectUri: 'https://app.example.com/logout',
24
+ dpop: { required: true },
25
+ responseVault: true,
26
+ })
27
+ ```
28
+
29
+ Enabling the SDK option does not add server support. The issuer and the
30
+ client-origin service MUST implement the same v1 contract for the registered
31
+ client.
32
+
33
+ The registration and SDK configuration have these requirements:
34
+
35
+ - `issuer` is an HTTPS origin. HTTP is accepted only for loopback development,
36
+ and its scheme MUST match the redirect scheme.
37
+ - `redirectUri` is an exact secure-context URL without credentials, query, or
38
+ fragment. `client origin` means its origin.
39
+ - `postLogoutRedirectUri` is a distinct, clean absolute URL on the client
40
+ origin.
41
+ - `clientId` and `audience` are non-empty registered values.
42
+ - `scopes` is a canonical, space-delimited list with no duplicates and MUST
43
+ contain `openid`.
44
+ - DPoP is mandatory. Every authorization uses a fresh, non-extractable P-256
45
+ key.
46
+ - `deriveEncryptionKey` is unsupported because fragment delivery is
47
+ incompatible with a parameter-free callback.
48
+
49
+ ## Discovery
50
+
51
+ An issuer that supports this profile advertises `atol_console_vault` in
52
+ `response_modes_supported` and publishes this exact metadata member:
53
+
54
+ ```json
55
+ {
56
+ "atol_console_browser_authorization": {
57
+ "version": 1,
58
+ "response_mode": "atol_console_vault",
59
+ "client_id": "example-spa",
60
+ "redirect_uri": "https://app.example.com/oidc/complete",
61
+ "audience": "https://api.example.com",
62
+ "console_origin": "https://app.example.com",
63
+ "bootstrap_endpoint": "https://app.example.com/auth/browser/v1/bootstrap",
64
+ "pushed_authorization_request_endpoint": "https://app.example.com/auth/browser/v1/pushed-authorization-requests",
65
+ "issuer_bootstrap_endpoint": "https://id.example.com/auth/browser/v1/issuer-bootstrap",
66
+ "authorization_init_endpoint": "https://id.example.com/auth/browser/v1/authorization-init",
67
+ "authorization_endpoint": "https://id.example.com/auth/authorize",
68
+ "relay_endpoint": "https://app.example.com/auth/browser/v1/relay",
69
+ "acknowledgement_endpoint": "https://app.example.com/auth/browser/v1/acknowledge",
70
+ "finalization_endpoint": "https://app.example.com/auth/browser/v1/finalize",
71
+ "rejection_endpoint": "https://app.example.com/auth/browser/v1/reject"
72
+ }
73
+ }
74
+ ```
75
+
76
+ The metadata member and `console_origin` name are fixed v1 wire names. They do
77
+ not restrict the public SDK profile to one application.
78
+
79
+ All values are registration authority. The client ID, redirect URI, audience,
80
+ client origin, issuer origin, response mode, version, and endpoint origins
81
+ MUST agree. A client MUST NOT derive authority from an unregistered discovery
82
+ value or silently fall back to query, fragment, form-post, or `web_message`.
83
+ An issuer MUST fail discovery rather than advertise stale or partially
84
+ available response-vault metadata.
85
+
86
+ The standard top-level discovery members are part of the same binding:
87
+
88
+ - `issuer` MUST equal the normalized configured issuer;
89
+ - `authorization_endpoint` MUST equal both the custom
90
+ `authorization_endpoint` and `${issuer}/auth/authorize`; and
91
+ - `token_endpoint` MUST equal `${issuer}/auth/token`, the exact `htu` used for
92
+ the relay DPoP proof.
93
+
94
+ Missing, duplicated, or conflicting discovery authority is terminal. The SDK
95
+ does not cache a failed discovery result.
96
+
97
+ ## Common wire rules
98
+
99
+ All JSON protocol endpoints use `POST`. The initial authorization navigation
100
+ uses `GET`; issuer interaction may use document `POST`. Every JSON request
101
+ contains `"version": 1`. JSON objects:
102
+
103
+ - MUST use `Content-Type: application/json` without media-type parameters;
104
+ - MUST be no larger than 16 KiB at the service boundary;
105
+ - MUST contain exactly the defined members;
106
+ - MUST reject unknown or duplicate members; and
107
+ - MUST reject trailing JSON values.
108
+
109
+ A canonical 43-character value is the unpadded base64url encoding of 32
110
+ bytes and matches `^[A-Za-z0-9_-]{43}$`. Secrets and IDs use random bytes;
111
+ S256 challenges and DPoP JWK thumbprints use 32-byte digests.
112
+
113
+ JSON responses use `Content-Type: application/json`. Empty `204` responses
114
+ MUST have no body. Every response is non-cacheable. The SDK sends protocol
115
+ requests with `cache: "no-store"`, `redirect: "error"`, and
116
+ `referrerPolicy: "no-referrer"`.
117
+
118
+ The service accepts request bodies up to 16 KiB. The SDK consumes response
119
+ bodies as a stream and rejects an invalid `Content-Length`, invalid UTF-8, or
120
+ more than 32 KiB before parsing the envelope. The operation deadline covers
121
+ both response headers and complete body consumption.
122
+
123
+ ### Browser boundary
124
+
125
+ Client-origin endpoints require an exact same-origin credentialed fetch with
126
+ the client `Origin`, `Sec-Fetch-Site: same-origin`, `Sec-Fetch-Mode: cors`,
127
+ and `Sec-Fetch-Dest: empty`.
128
+
129
+ Issuer bootstrap and authorization-init are credentialed CORS requests from
130
+ the registered client origin. They require `Sec-Fetch-Site: same-site` and an
131
+ exact preflight. The issuer allows only `POST`, credentials, and the precise
132
+ headers needed by the endpoint. It does not reflect arbitrary origins.
133
+
134
+ The initial authorization navigation is a same-site document or iframe
135
+ navigation to the exact parameter-free authorization endpoint. The callback
136
+ is the exact registered redirect path with no query or fragment.
137
+
138
+ ### Error envelopes
139
+
140
+ A protocol denial has exactly one member:
141
+
142
+ ```json
143
+ { "error": "invalid_request" }
144
+ ```
145
+
146
+ The allowed protocol codes are:
147
+
148
+ | Code | Meaning |
149
+ | --------------------------- | ------------------------------------------------------------------------ |
150
+ | `invalid_request` | Malformed, expired, consumed, substituted, or invalid state |
151
+ | `forbidden` | Origin, Fetch Metadata, cookie, or CSRF browser boundary failed |
152
+ | `busy` | A live bootstrap or browser authority already owns the supplied boundary |
153
+ | `unavailable` | Required durable state or another required dependency is unavailable |
154
+ | `authorization_nonterminal` | Exact authenticated custody remains live; retain it |
155
+ | `authorization_terminal` | Exact authenticated custody is terminal; deletion is permitted |
156
+
157
+ The envelope is intentionally unversioned. Missing and substituted authority
158
+ are not distinguishable to the caller. `authorization_nonterminal` and
159
+ `authorization_terminal` are cleanup authority only when the exact endpoint,
160
+ status, content type, no-store policy, body, and caller-held capability binding
161
+ all authenticate. A generic or malformed 409/410 never authorizes deletion.
162
+
163
+ A stored terminal authorization result is different. It is a versioned,
164
+ redeliverable relay envelope:
165
+
166
+ ```json
167
+ {
168
+ "version": 1,
169
+ "error": "access_denied",
170
+ "csrf_token": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
171
+ }
172
+ ```
173
+
174
+ Its `error` is exactly one of `invalid_request`, `access_denied`,
175
+ `login_required`, `temporarily_unavailable`, or `server_error`.
176
+
177
+ A DPoP denial is also distinct:
178
+
179
+ ```json
180
+ {
181
+ "error": "use_dpop_nonce",
182
+ "error_description": "authorization server requires a nonce in the DPoP proof"
183
+ }
184
+ ```
185
+
186
+ `use_dpop_nonce` has the exact description shown above and includes exactly
187
+ one `DPoP-Nonce` response header. `invalid_dpop_proof` has description
188
+ `the DPoP proof is invalid` and no nonce. A nonce is 1 through 512 RFC 6749
189
+ NQCHAR characters; comma, whitespace, controls, and duplicate comma-joined
190
+ fields are invalid. A DPoP envelope has exactly `error` and
191
+ `error_description`; it is not a stored terminal authorization result.
192
+
193
+ ## Endpoints and exact schemas
194
+
195
+ `client origin` is the origin of the registered redirect URI. The exact
196
+ endpoint URLs are the discovery values above.
197
+
198
+ ### Bootstrap
199
+
200
+ Before client-origin bootstrap, the SDK persists one `prepared` record with
201
+ the exact tab, cancellation, and PAR-idempotency capabilities. The
202
+ client-origin endpoint accepts:
203
+
204
+ ```json
205
+ {
206
+ "version": 1,
207
+ "mode": "create",
208
+ "tab_secret": "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE",
209
+ "cancellation_secret": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
210
+ "par_idempotency_key": "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
211
+ }
212
+ ```
213
+
214
+ `mode` is exactly `create` or `terminal_only`. Both modes reuse the same
215
+ persisted capabilities. They send no CSRF header and may carry the HttpOnly
216
+ cookie from an earlier exact attempt.
217
+
218
+ `create` success is `201`:
219
+
220
+ ```json
221
+ {
222
+ "version": 1,
223
+ "csrf_token": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
224
+ "expires_in": 60,
225
+ "bootstrap_terminal_proof": "opaque-server-proof"
226
+ }
227
+ ```
228
+
229
+ The server encrypts the generated cookie and CSRF response and binds it to the
230
+ capabilities, original presented cookie, committed cookie, immutable database
231
+ deadline, and selected terminal-proof key identity. An exact retry accepts
232
+ either the original cookie state or the committed cookie. It returns the same
233
+ cookie, CSRF, proof identity, and deadline with decreasing `expires_in`; it
234
+ does not regenerate authority or extend the deadline. A different binding
235
+ under the same idempotency capability is `400 invalid_request`.
236
+
237
+ `terminal_only` never creates live authority. It returns exact no-store
238
+ `409 {"error":"authorization_nonterminal"}` for an exact live row and exact
239
+ no-store `410 {"error":"authorization_terminal"}` for terminal state. If the
240
+ original create never committed, the server atomically installs the exact
241
+ capability-bound terminal fence before returning 410. A delayed create cannot
242
+ resurrect that attempt. Only an authenticated exact 410 permits local
243
+ deletion. An exact 409, a generic error, a malformed response, or an
244
+ unauthenticated 410 preserves prepared custody.
245
+
246
+ The issuer bootstrap endpoint remains separate and accepts only:
247
+
248
+ ```json
249
+ { "version": 1 }
250
+ ```
251
+
252
+ Its `201` response has `version`, `csrf_token`, and `expires_in`; it does not
253
+ return a terminal proof and is not part of client-origin prepared recovery.
254
+
255
+ The client-origin cookie is `__Host-atol-console-bff`; the issuer cookie is
256
+ `__Host-atol-issuer-init`. Both are host-only, `Path=/`, `Secure`, `HttpOnly`,
257
+ `SameSite=Strict`, and have a 60-second bootstrap lifetime. CSRF is returned
258
+ only in JSON. PAR, authorization-init, and relay send it once as
259
+ `X-Atol-CSRF`; bootstrap and capability settlement send no CSRF header.
260
+
261
+ Client-origin bootstrap errors are `400 invalid_request`, `403 forbidden`,
262
+ `409 busy`, exact authenticated `409 authorization_nonterminal`, exact
263
+ authenticated `410 authorization_terminal`, or `503 unavailable`. Issuer
264
+ bootstrap errors are `400 invalid_request`, `403 forbidden`, `409 busy`, or
265
+ `503 unavailable`.
266
+
267
+ ### Pushed authorization request
268
+
269
+ The client-origin pushed request has this exact shape:
270
+
271
+ ```json
272
+ {
273
+ "version": 1,
274
+ "client_id": "example-spa",
275
+ "redirect_uri": "https://app.example.com/oidc/complete",
276
+ "response_type": "code",
277
+ "scope": "openid profile email",
278
+ "state": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
279
+ "nonce": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
280
+ "code_challenge": "CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC",
281
+ "code_challenge_method": "S256",
282
+ "dpop_jkt": "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD",
283
+ "audience": "https://api.example.com",
284
+ "tab_secret": "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE",
285
+ "par_idempotency_key": "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
286
+ "cancellation_secret": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
287
+ "bootstrap_terminal_proof": "opaque-server-proof"
288
+ }
289
+ ```
290
+
291
+ The only optional members are:
292
+
293
+ ```json
294
+ {
295
+ "prompt": "login",
296
+ "max_age": 0,
297
+ "acr_values": "mfa",
298
+ "organization_id": "01KV4BNVVNZ4TNY0PP0CVXPZWP"
299
+ }
300
+ ```
301
+
302
+ `prompt`, when present, is `login` or `none`. `max_age` is an integer from 0
303
+ through 86400. `scope` has one through four unique values from `openid`,
304
+ `profile`, `email`, and `offline_access`, separated by one ASCII space;
305
+ `openid` is required. `acr_values` is `mfa` or `urn:atol:acr:mfa`.
306
+ `organization_id`, when supported by the registration, is a canonical ULID.
307
+ `audience` is the exact value from discovery.
308
+
309
+ Success is `201`:
310
+
311
+ ```json
312
+ {
313
+ "version": 1,
314
+ "transaction_id": "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH",
315
+ "request_uri": "urn:ietf:params:oauth:request_uri:IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII",
316
+ "expires_in": 60,
317
+ "transaction_expires_in": 600,
318
+ "csrf_token": "JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ",
319
+ "terminal_proof": "opaque-server-proof"
320
+ }
321
+ ```
322
+
323
+ The service consumes the bootstrap and rotates both the client-origin cookie
324
+ and CSRF token. The replacement cookie is valid for the bounded transaction,
325
+ which is at most ten minutes.
326
+
327
+ Bootstrap `expires_in` is the database-observed remaining bootstrap lifetime
328
+ from 1 through 60 seconds. PAR `expires_in` is the remaining request-URI
329
+ lifetime from 0 through 60 seconds; zero is returned only when an exact replay
330
+ finds a transaction whose request URI can no longer be used.
331
+ `transaction_expires_in` is the independently remaining transaction lifetime
332
+ from 1 through 600 seconds. Equality is expired.
333
+
334
+ The SDK creates `par_idempotency_key`, `cancellation_secret`, and
335
+ `tab_secret` before its first PAR attempt and persists them before transport.
336
+ The service stores digests of those capabilities, not their plaintext. The
337
+ bootstrap proof binds the original bootstrap cookie, CSRF, capabilities,
338
+ client origin, client ID, persisted proof-key identity, and maximum possible
339
+ transaction deadline. The transaction proof binds the exact transaction,
340
+ client, tab, cancellation capability, persisted proof-key identity, and
341
+ original transaction deadline.
342
+
343
+ An exact PAR retry MUST compare the idempotency key, canonical authorization
344
+ parameters, tab secret, cancellation secret, client registration, response
345
+ mode, and protocol version. During an ambiguous response it accepts the
346
+ original or replacement cookie and the original or replacement CSRF binding.
347
+ It returns the same transaction ID, request URI, replacement cookie, CSRF,
348
+ and original absolute request-URI and transaction deadlines. Remaining
349
+ intervals decrease from those deadlines; replay never refreshes either one.
350
+ Recovery runs before mutable client-registration admission, Fosite, database
351
+ clock reads, random generation, or envelope sealing. It MUST NOT create
352
+ another transaction or repeat secret generation. A changed request under the
353
+ same idempotency key is `400 invalid_request`.
354
+
355
+ Proof recovery uses the proof-key identity persisted with the exact row, not
356
+ the key active at retry time. The server retains referenced predecessor keys
357
+ through the bounded recovery window. A missing referenced key is
358
+ `503 unavailable`; the server MUST NOT substitute a different key.
359
+
360
+ PAR errors are `400 invalid_request`, `403 forbidden`, or `503 unavailable`.
361
+
362
+ ### Issuer initialization
363
+
364
+ After issuer bootstrap, authorization-init accepts:
365
+
366
+ ```json
367
+ {
368
+ "version": 1,
369
+ "request_uri": "urn:ietf:params:oauth:request_uri:IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII"
370
+ }
371
+ ```
372
+
373
+ It requires the issuer cookie and issuer-bootstrap CSRF header. Success is an
374
+ empty `204`. It consumes the issuer bootstrap, replaces it with an
375
+ issuer-transaction cookie, and binds that cookie to exactly one live request
376
+ URI and issuer authority for at most ten minutes.
377
+
378
+ Errors are `400 invalid_request`, `403 forbidden`, or `503 unavailable`.
379
+
380
+ ### Authorization navigation
381
+
382
+ The browser navigates to `/auth/authorize` with no query or fragment. The
383
+ issuer loads all OAuth parameters from the server-held request and validates
384
+ the exact registered client, redirect URI, response type, scope, audience,
385
+ PKCE challenge, DPoP JKT, state, nonce, and optional intent.
386
+
387
+ The successful or terminal result is encrypted in the server response vault.
388
+ The issuer returns `303` to the exact clean callback and expires the
389
+ issuer-transaction cookie. It never puts code, state, error, or other
390
+ authorization data in the redirect.
391
+
392
+ ### Relay
393
+
394
+ Relay requires the client-origin transaction cookie and current CSRF header:
395
+
396
+ ```json
397
+ {
398
+ "version": 1,
399
+ "transaction_id": "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH",
400
+ "tab_secret": "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE",
401
+ "code_verifier": "KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK",
402
+ "dpop_proof": "compact-jws"
403
+ }
404
+ ```
405
+
406
+ The verifier is 43 through 128 RFC 7636 unreserved characters. The compact
407
+ DPoP proof is at most 12 KiB and is for `POST` to the issuer token endpoint.
408
+
409
+ Success is `200` with exactly the required members and optional token members:
410
+
411
+ ```json
412
+ {
413
+ "version": 1,
414
+ "access_token": "access-token",
415
+ "token_type": "DPoP",
416
+ "expires_in": 3600,
417
+ "refresh_token": "optional-refresh-token",
418
+ "id_token": "optional-id-token",
419
+ "scope": "openid profile email",
420
+ "csrf_token": "LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL"
421
+ }
422
+ ```
423
+
424
+ `access_token`, `token_type`, `expires_in`, `scope`, and `csrf_token` are
425
+ required. `refresh_token` and `id_token` are optional. The SDK accepts an
426
+ expiry from 1 through 86400 seconds, a scope up to 512 characters, and each
427
+ token up to 32 KiB, subject to the 32 KiB total response limit.
428
+ A success may include one valid `DPoP-Nonce` header for the next proof.
429
+
430
+ The first valid relay atomically:
431
+
432
+ 1. validates the cookie, CSRF, transaction, tab, PAR, PKCE, DPoP JKT, issuer,
433
+ and live login-session fence;
434
+ 2. exchanges a success code once or classifies the stored terminal error;
435
+ 3. replaces the authorization vault with a separately encrypted exact
436
+ delivery envelope;
437
+ 4. rotates CSRF and retains the prior CSRF only for exact relay recovery; and
438
+ 5. enters `issued` for success or `failed` for a terminal error.
439
+
440
+ An exact redelivery accepts the same cookie, transaction, tab secret, and
441
+ either the pre-delivery or rotated CSRF. It decrypts the existing delivery
442
+ and returns byte-equivalent JSON semantics. It does not reuse the code, mint
443
+ another token family, rotate CSRF again, or change session authority.
444
+ The server performs this terminal delivery recovery before consulting mutable
445
+ issuer status or client registration. Suspension or a later registration
446
+ change may deny a nonterminal token issuance, but cannot strand an already
447
+ committed `issued` or `failed` delivery.
448
+
449
+ A valid `use_dpop_nonce` challenge leaves the transaction unchanged. The SDK
450
+ retries once with the same transaction and DPoP key plus the nonce. A malformed
451
+ or repeated challenge is rejected and the transaction is settled through the
452
+ rejection endpoint.
453
+
454
+ Relay errors are:
455
+
456
+ - `400` for a stored terminal envelope, a DPoP envelope, or unversioned
457
+ `invalid_request`;
458
+ - `403 forbidden` for the browser boundary; and
459
+ - `503 unavailable` for retryable transaction or dependency failure.
460
+
461
+ ### Acknowledge, finalize, and reject
462
+
463
+ Acknowledge and finalize use the same exact capability body:
464
+
465
+ ```json
466
+ {
467
+ "version": 1,
468
+ "transaction_id": "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH",
469
+ "tab_secret": "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE",
470
+ "cancellation_secret": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
471
+ }
472
+ ```
473
+
474
+ They are exact same-origin fetches, but the settlement authority is the
475
+ transaction, tab, and cancellation capability. They do not require a cookie
476
+ or CSRF header.
477
+
478
+ `/acknowledge` changes `issued` or `failed` to `publishing`. The first commit:
479
+
480
+ - deletes the encrypted delivery;
481
+ - clears cookie, CSRF, issuer-cookie, PAR, and relay-recovery authority;
482
+ - records acknowledgement using database time;
483
+ - retains the cancellation capability until the original transaction expiry;
484
+ and
485
+ - expires any client-origin transaction cookie in the `204` response.
486
+
487
+ An exact acknowledgement retry in `publishing` or `adopted` returns the same
488
+ empty `204`.
489
+
490
+ `/finalize` changes `publishing` to `adopted`. It is valid only before the
491
+ transaction expires. An exact retry of an adopted transaction returns the same
492
+ empty `204`.
493
+
494
+ `/reject` is the monotonic compensation and terminal-classification path. A
495
+ mutating rejection adds the required mode:
496
+
497
+ ```json
498
+ {
499
+ "version": 1,
500
+ "mode": "reject",
501
+ "transaction_id": "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH",
502
+ "tab_secret": "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE",
503
+ "cancellation_secret": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG"
504
+ }
505
+ ```
506
+
507
+ `reject` accepts an exact live
508
+ transaction in `pushed`, `ready`, `vault`, `issued`, `failed`, or `publishing`.
509
+ It also accepts `adopted` only before the original transaction expiry. Its
510
+ transaction:
511
+
512
+ - revokes every token artifact in the exact issued request family;
513
+ - deletes every encrypted authorization or delivery vault;
514
+ - clears all mutable cookie, CSRF, PAR, and relay authority;
515
+ - records rejection using database time; and
516
+ - expires any client-origin transaction cookie and enters `rejected`.
517
+
518
+ An exact retry of a rejected tombstone returns the same empty `204`.
519
+ Finalization and rejection serialize on the same transaction. Once rejection
520
+ wins, finalization cannot resurrect the grant.
521
+
522
+ Cleanup driven only by a local deadline uses:
523
+
524
+ ```json
525
+ {
526
+ "version": 1,
527
+ "mode": "terminal_only",
528
+ "client_id": "example-spa",
529
+ "transaction_id": "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH",
530
+ "tab_secret": "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE",
531
+ "cancellation_secret": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG",
532
+ "terminal_proof": "opaque-server-proof"
533
+ }
534
+ ```
535
+
536
+ `terminal_only` never mutates a live transaction. It returns exact no-store
537
+ 409 `authorization_nonterminal` while the database row remains live and exact
538
+ no-store 410 `authorization_terminal` only after database-clock expiry,
539
+ terminal transition, and the token-family invariant. After bounded tombstone
540
+ collection, the signed proof and database clock can authenticate absence as
541
+ terminal at or after the original deadline. Before that deadline, or when the
542
+ database clock or referenced proof key is unavailable, the server returns 503. Missing or substituted authority is generic 400. Realm suspension and
543
+ client-registration changes do not block either settlement mode because they
544
+ authenticate retained authority rather than admitting a new grant.
545
+
546
+ Settlement errors are `400 invalid_request`, `403 forbidden`, exact
547
+ `409 authorization_nonterminal`, exact `410 authorization_terminal`, or
548
+ `503 unavailable`. A `204` always has an empty body.
549
+
550
+ ## Server state machine
551
+
552
+ | State | Durable meaning | Next valid transitions |
553
+ | ------------ | --------------------------------------------------------------------- | --------------------------------------------------- |
554
+ | bootstrap | Exact encrypted cookie/CSRF response or terminal fence | `pushed`, consumed, or terminal |
555
+ | `pushed` | Exact encrypted PAR and cancellation binding exist | `ready`, `rejected`, or `expired` |
556
+ | `ready` | Issuer cookie is bound to the PAR | `vault`, `rejected`, or `expired` |
557
+ | `vault` | Encrypted code or terminal authorization result exists | `issued`, `failed`, `rejected`, or `expired` |
558
+ | `issued` | One token family and exact encrypted delivery exist | `publishing`, `rejected`, or `expired` |
559
+ | `failed` | Exact encrypted terminal error delivery exists | `publishing`, `rejected`, or `expired` |
560
+ | `publishing` | Delivery and mutable browser authority are gone; compensation is open | `adopted`, `rejected`, or `expired` |
561
+ | `adopted` | Publication was finalized | exact retry, bounded `rejected`, or terminal expiry |
562
+ | `rejected` | Exact family is revoked and mutable authority is gone | exact retry or terminal expiry |
563
+ | `expired` | No live transaction authority remains | none |
564
+
565
+ All expiry comparisons use database time. Equality is expired.
566
+ Consumed and terminal bootstrap and transaction fences are retained for a
567
+ bounded 24-hour exact-retry window after the immutable deadline. Reaping
568
+ clears encrypted response material and all mutable cookie authority before
569
+ deleting the non-authority fence in bounded batches.
570
+
571
+ An expired `issued` or `publishing` transaction MUST have its exact token
572
+ family revoked before cleanup. Reaping a rejected token family re-verifies
573
+ that no live family remains. An adopted transaction is never revoked by the
574
+ expiry reaper. At transaction expiry, adopted rejection is denied.
575
+
576
+ ## Browser custody and authority
577
+
578
+ The SDK maintains one host-wide response-vault slot per client origin. The
579
+ slot is shared across tabs and across response-vault configurations on that
580
+ origin. IndexedDB compare-and-set admits exactly one unexpired owner before
581
+ any server request. A competing start receives
582
+ `ResponseVaultAuthorizationBusyError`; it does not create a second PAR.
583
+
584
+ The durable record contains the registered binding, authorization intent,
585
+ random protocol secrets, settlement classification, generation snapshot, and
586
+ non-extractable DPoP `CryptoKey` handles. Access, refresh, and ID tokens are
587
+ never persisted. Beyond ordinary OIDC state and the non-secret tab generation,
588
+ response-vault mode adds only one opaque record reference to `sessionStorage`.
589
+ Before PAR, the live record and slot use the remaining 60-second bootstrap
590
+ deadline. A successful PAR atomically replaces both with the original
591
+ ten-minute transaction deadline. Clean publication uses one IndexedDB
592
+ transaction to release the slot and replace full grant custody with an exact,
593
+ whitelist-built `published` cancellation-only record. That record retains only
594
+ the registered binding, generation snapshot, transaction and cancellation
595
+ capabilities, original deadline, execution fence, and a closed rejection
596
+ provenance; it cannot resume a grant. Ordinary protocol and lifecycle
597
+ rejection use `internal`. Only an atomic claim of a stored `interactive`
598
+ authorization may write `interactive_cancel`.
599
+
600
+ `prepared` is not locally reapable once bootstrap transport begins because
601
+ the server may have committed `create` before its response was lost. Network
602
+ failure, malformed response, generic protocol denial, lifecycle invalidation,
603
+ and generation mismatch preserve the record and release only its fenced
604
+ execution claim. While its phase is live, a later owner retries exact
605
+ `create`. At local equality or expiry, it sends exact `terminal_only`. Only an
606
+ authenticated 410 deletes the record; authenticated 409 and every
607
+ unauthenticated or malformed result retain it.
608
+
609
+ A brand-new start resolves and validates immutable discovery authority before
610
+ staging `prepared`. Failure at that preflight leaves no custody because no
611
+ bootstrap request could have been sent. Recovery of an existing prepared
612
+ owner does not gain that proof of absence, so discovery failure preserves it.
613
+
614
+ Every side-effecting browser operation holds a random execution owner, a
615
+ monotonically increasing fence, and a bounded lease. Every mutation, release,
616
+ and delete must present the exact owner and fence. An expired lease can be
617
+ taken over, but the stale handle cannot mutate custody afterward.
618
+
619
+ Navigation is separate from execution. Immediately before interactive or
620
+ iframe navigation, the SDK persists `navigating`, a random navigation owner,
621
+ and an absolute deadline, then releases the execution lease. Only a callback
622
+ holding that exact navigation owner may atomically enter `redeeming`.
623
+ Long-running external login or MFA therefore does not depend on renewing a
624
+ short execution lease, and another live SDK instance reports busy rather than
625
+ rejecting peer authority.
626
+
627
+ Two independent, random 32-byte generations fence asynchronous work:
628
+
629
+ - the credential-authority generation is origin-wide for an exact issuer,
630
+ client, and client origin and is stored with `active` or `signed_out` status
631
+ in one canonical `localStorage` record; and
632
+ - the tab-owner generation survives a redirect in `sessionStorage` and is
633
+ scoped to the issuer, client, and redirect URI.
634
+
635
+ They are random values, not counters. A missing authority record is initialized
636
+ as active with fresh randomness and reread so a concurrent persisted writer
637
+ wins. Logout atomically writes a fresh generation and `signed_out` tombstone
638
+ before asynchronous teardown, then replaces the tab-owner generation. Client
639
+ destruction replaces only the tab-owner generation. Invalidation replacement
640
+ never parses the old value, so corrupt storage cannot preserve stale authority.
641
+ Every assertion rejects `signed_out` authority even when its generation
642
+ matches.
643
+
644
+ Cold startup under `signed_out` authority runs application-scoped lifecycle
645
+ cleanup, including superseded `adopted` and clean `published` custody, without
646
+ rotating the shared authority again. It then suppresses silent authorization
647
+ even when the IdP session cookie remains live. This remains correct when
648
+ `BroadcastChannel` is absent or delayed. Only explicit login atomically
649
+ installs a fresh active generation; a stale cleanup cannot overwrite it.
650
+
651
+ Every ordinary and response-vault authorization snapshots both generations.
652
+ The SDK checks the snapshot before and after asynchronous proof generation,
653
+ relay, validation, credential publication, and settlement. A stale operation
654
+ cannot commit credentials. Rejection deliberately retains its exact
655
+ cancellation capability after generation rotation so logout can still revoke
656
+ server authority. RP-initiated logout uses one-use validated callback state,
657
+ surfaces revocation or navigation failures, and retains exact in-memory retry
658
+ custody for the current runtime.
659
+
660
+ `cancelLogin()` is the non-navigating cancellation boundary for an abandoned
661
+ interactive response-vault authorization. It is valid only on an
662
+ uninitialized, signed-out response-vault client. The SDK claims durable
663
+ `interactive_cancel` rejection provenance before replacing the tab-owner
664
+ generation, cancels owned work, rejects the exact active transaction, and
665
+ resolves only after local custody release. The atomic claim verifies the
666
+ stored mode is `interactive`; iframe renewal and internally rejected custody
667
+ cannot be relabeled or cancelled through this API. An ambiguous rejection
668
+ remains `rejecting` or `reject_retry` in the single active slot, so the same or
669
+ a fresh client may resume only that terminal operation with a fresh custody
670
+ revision and held Web Lock; a stale process-local handle cannot win. A
671
+ same-runtime cancellation retains its pre-rotation tab-owner fence if local
672
+ rotation fails after rejection has already released durable custody. A
673
+ custody-free retry replaces that fence and rereads `sessionStorage` to prove
674
+ the stale owner is gone before it may resolve. A
675
+ damaged full grant may fall back to cancellation custody only when its durable
676
+ source mode still proves `interactive`; missing key material never permits an
677
+ iframe grant or unproven record to acquire interactive cancellation
678
+ provenance. Destroy-cleanup ownership is latched only after the durable claim,
679
+ so a pre-claim absence, contention, or validation failure cannot suppress
680
+ later lifecycle invalidation. A
681
+ client-local FIFO orders `beginLogin()` and `cancelLogin()`, so cancellation
682
+ cannot resolve before an earlier yielding login has either navigated or
683
+ failed. The first cancellation promise remains the single-flight identity
684
+ before logout and mutable preconditions are rechecked. A logout admitted after
685
+ that queued cancellation awaits the exact promise instead of retroactively
686
+ invalidating it; a cancellation requested after logout starts is unavailable.
687
+ The operation does not write a signed-out logout tombstone, call `end_session`,
688
+ or expose transaction capabilities. Completed cancellation suppresses
689
+ duplicate destroy cleanup until a later explicit `beginLogin()` successfully
690
+ establishes new interactive custody. `logout()` awaits an in-flight
691
+ cancellation and propagates its failure.
692
+
693
+ ## Browser durable states
694
+
695
+ | State | Meaning after a crash or reload |
696
+ | ---------------- | ------------------------------------------------------------------------------------------------------------------ |
697
+ | `prepared` | Local capabilities exist; bootstrap create may have committed and must be exactly retried or terminally classified |
698
+ | `par_pending` | Bootstrap CSRF and exact PAR retry material are durable |
699
+ | `pushed` | Transaction ID, request URI, rotated CSRF, and cancellation capability are durable |
700
+ | `initializing` | Issuer initialization may have committed; a crash must exact-reject rather than replay mutable initialization |
701
+ | `initialized` | Issuer initialization committed; callback may relay |
702
+ | `navigating` | Browser navigation owns the transaction until its persisted callback deadline |
703
+ | `redeeming` | A relay may have reached the service |
704
+ | `relay_retry` | Retry the exact relay; do not start another grant |
705
+ | `awaiting_ack` | Parsed result classification and rotated CSRF are durable; bearer material is memory-only |
706
+ | `publishing` | Acknowledgement committed; local credential publication must finish or compensate |
707
+ | `finalizing` | Finalization may have committed and is exactly retryable |
708
+ | `adopted` | Finalization is confirmed, but local publication and slot release are not confirmed; ordinary recovery compensates |
709
+ | `published` | Local publication and slot release are confirmed; only explicit lifecycle invalidation or logout may cancel |
710
+ | `rejecting` | Rejection intent and closed provenance were persisted before transport |
711
+ | `reject_retry` | Rejection outcome is ambiguous; retry the same capability and provenance |
712
+ | `reject_blocked` | An authoritative rejection denial occurred; retain custody and do not invent cleanup |
713
+
714
+ State changes and the host-wide slot update in one IndexedDB transaction.
715
+ A page crash in an in-flight state is recovered into the corresponding exact
716
+ retry state. Corrupt, mismatched, or expired custody fails closed.
717
+
718
+ ## Publication and compensation
719
+
720
+ A relayed success is not immediately live:
721
+
722
+ 1. The SDK parses the exact envelope and validates token type, issuer,
723
+ audience, subject, OIDC nonce, organization context, and `cnf.jkt`.
724
+ 2. The SDK prepares local credential and encryption state without publishing
725
+ it.
726
+ 3. Capability acknowledgement moves the server to `publishing` and deletes
727
+ the redeliverable delivery.
728
+ 4. The SDK atomically publishes the prepared credentials under the same
729
+ lifecycle and generation fences.
730
+ 5. Capability finalization moves the server to `adopted`.
731
+ 6. The SDK atomically replaces `adopted` grant custody with the exact
732
+ whitelist-built `published` cancellation-only record, releases the
733
+ host-wide slot, and retains that cancellation capability until expiry.
734
+
735
+ A fresh SDK instance for the same binding and tab owner treats retained
736
+ `adopted` custody as abandoned and rejects it before recovery. Ordinary crash
737
+ compensation excludes `published`. Explicit lifecycle invalidation and logout
738
+ include it. Cleanup inventory uses a durable primary-key continuation and
739
+ visits at most 64 records per invocation. Repeated invocations advance through
740
+ unrelated and owned custody without materializing the database, and wrap after
741
+ reaching the end. The loader returns a two-phase continuation: the caller
742
+ commits it with a compare-and-swap only after every returned custody operation
743
+ succeeds. Parse, rejection, and cleanup failures leave the cursor unchanged so
744
+ the exact custody is retried. A malformed cancellation candidate therefore
745
+ fails closed without being skipped, while scanning never deletes live custody.
746
+
747
+ Rejection uses only the stored binding and client origin, transaction ID, tab
748
+ secret, cancellation secret, deadline, and execution fence. It derives the
749
+ fixed same-origin version-1 rejection path and does not require issuer
750
+ discovery, rotated CSRF, or a usable DPoP private key. Grant resume and relay
751
+ still require and thumbprint-validate the non-extractable DPoP key.
752
+
753
+ If anything fails after acknowledgement but before complete local cleanup,
754
+ the SDK clears locally published credentials and rejects the exact
755
+ transaction before its original expiry. This includes an ambiguous
756
+ finalization or local durable-cleanup failure.
757
+
758
+ A terminal authorization error has no credential publication. The SDK
759
+ acknowledges and finalizes it before throwing the exact typed OAuth error.
760
+
761
+ ## Retry, crash, and reload behavior
762
+
763
+ - An ambiguous bootstrap stays `prepared`. The next live-phase attempt sends
764
+ the same `create` body and capabilities. At local expiry it sends
765
+ `terminal_only`; only authenticated terminal classification releases
766
+ custody.
767
+ - An ambiguous PAR stays `par_pending`. The next attempt sends the same body,
768
+ idempotency key, tab secret, cancellation secret, cookie, and CSRF lineage.
769
+ - Relay transport loss or `503 unavailable` keeps the same transaction,
770
+ PKCE verifier, and DPoP key. A retry redelivers or completes the same
771
+ one-use exchange.
772
+ - The SDK persists success or terminal-error classification before
773
+ acknowledgement. It never persists the token envelope.
774
+ - An ambiguous acknowledgement is retried with the capability body. A server
775
+ already in `publishing` or `adopted` returns `204`.
776
+ - A crash in `redeeming` or a relay retry state redelivers the exact envelope.
777
+ Once `awaiting_ack` is durable, a reload has lost any parsed bearer material
778
+ and does not relay again.
779
+ - Reload with a durable success settlement rejects the exact unavailable
780
+ family, then reports delivery unavailable so the browser client can obtain
781
+ one fresh silent grant.
782
+ - Reload with a durable terminal settlement rejects the exact transaction and
783
+ re-surfaces its persisted OAuth error. It does not use success
784
+ delivery-unavailable recovery.
785
+ - Finalization is exactly retryable. A crash that loses locally published
786
+ credentials does not treat server finalization as proof that those
787
+ credentials still exist; it compensates when the deadline permits.
788
+ - Rejection is persisted before transport. Network loss and `503` move to
789
+ `reject_retry`. An exact rejected tombstone returns `204`.
790
+ - Exact `400` or `403` `{"error":"invalid_request"}` during rejection moves
791
+ to `reject_blocked`. The SDK retains any owned live slot and its cancellation
792
+ evidence instead of reporting fake success or starting a replacement
793
+ transaction. Malformed responses and other ambiguous failures remain
794
+ `reject_retry`.
795
+
796
+ Protocol operations use a fixed 15-second implementation deadline. The
797
+ effective deadline is the earlier of that value and transaction expiry. The
798
+ deadline includes streaming body consumption. Lifecycle invalidation aborts
799
+ owned fetches and retry waits immediately.
800
+
801
+ PAR, acknowledgement, finalization, and rejection use at most three immediate
802
+ attempts with 100 ms and 200 ms waits between attempts. A later caller or page
803
+ reload may resume only the exact durable transaction. No retry creates a new
804
+ grant, key, PAR, or cancellation capability.
805
+
806
+ Iframe authorization has a configured callback bound of at most 60 seconds.
807
+ Its timer uses the earlier persisted navigation or transaction deadline;
808
+ equality times out immediately.
809
+
810
+ IndexedDB upgrades recognize only the exact historical version-2
811
+ generation-scoped key, the later version-2 origin key, and the version-3
812
+ origin key. Slot reference and expiry must exactly match the referenced live
813
+ record. Migration never infers `published` from a missing legacy slot. When
814
+ multiple exact transaction-bound owners collapse onto one origin, the upgrade
815
+ retains one deterministic origin slot as a barrier and atomically converts
816
+ the other owners to whitelist-built, cancellation-only `reject_retry` records.
817
+ Transaction IDs, cancellation capabilities, generation bindings, and
818
+ deadlines remain exact; migration never extends them. A live `par_pending`
819
+ owner is retained because its server outcome is unknown. Multiple live
820
+ `par_pending` owners, `reject_blocked` custody, malformed live cancellation
821
+ authority, and any unknown member on a live legacy record, including a
822
+ structured-cloneable alias of known key material, abort the atomic upgrade
823
+ without partial writes. Persisted cancellation-only records have one exact
824
+ member set, plus either both execution-lease members or neither. Legacy
825
+ `navigating` custody without a reusable navigation lease is converted to
826
+ exact cancellation custody rather than silently discarded.
827
+
828
+ ## Privacy invariants
829
+
830
+ Authorization code, OAuth state, OIDC nonce, PKCE material, request URI,
831
+ transaction ID, tab secret, idempotency key, cancellation secret, DPoP private
832
+ material, and tokens MUST NOT appear in a navigation URL, fragment, form post,
833
+ or `postMessage`.
834
+
835
+ Bearer material is memory-only in the browser. Cookies are `HttpOnly`.
836
+ Persistent browser storage contains only bounded protocol custody and
837
+ non-extractable key handles. Protocol requests and responses are non-cacheable
838
+ and use no-referrer behavior.
839
+
840
+ Malformed envelopes, invalid bindings, conflicting transactions, unsupported
841
+ states, unavailable durable settlement, and failed proof validation are
842
+ fatal. The SDK does not invent a response, silently release blocked custody,
843
+ or downgrade response-vault DPoP to Bearer.