@deque/axe-auth 1.1.0-next.ac35e028 → 1.1.0-next.adf1ee93

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.
Files changed (44) hide show
  1. package/README.md +20 -26
  2. package/credits.json +53 -0
  3. package/dist/cli/commonArgs.d.ts +53 -37
  4. package/dist/cli/commonArgs.help.d.ts +1 -1
  5. package/dist/cli/commonArgs.help.js +12 -11
  6. package/dist/cli/commonArgs.js +37 -66
  7. package/dist/cli/errors.d.ts +0 -10
  8. package/dist/cli/errors.js +1 -16
  9. package/dist/cli/testUtils.js +3 -3
  10. package/dist/cli/types.d.ts +8 -11
  11. package/dist/commands/login.d.ts +3 -0
  12. package/dist/commands/login.help.d.ts +1 -1
  13. package/dist/commands/login.help.js +11 -5
  14. package/dist/commands/login.js +38 -14
  15. package/dist/commands/logout.d.ts +1 -1
  16. package/dist/commands/logout.help.d.ts +1 -1
  17. package/dist/commands/logout.help.js +5 -4
  18. package/dist/commands/logout.js +1 -15
  19. package/dist/commands/token.d.ts +2 -7
  20. package/dist/commands/token.help.d.ts +1 -1
  21. package/dist/commands/token.help.js +5 -5
  22. package/dist/commands/token.js +10 -22
  23. package/dist/index.js +23 -51
  24. package/dist/oauth/authorize.d.ts +7 -0
  25. package/dist/oauth/authorize.js +2 -1
  26. package/dist/oauth/discoverOIDC.js +31 -1
  27. package/dist/oauth/discoverSSOConfig.d.ts +47 -0
  28. package/dist/oauth/discoverSSOConfig.js +105 -0
  29. package/dist/oauth/errors.d.ts +2 -0
  30. package/dist/oauth/getValidAccessToken.js +1 -0
  31. package/dist/oauth/openBrowser.d.ts +14 -3
  32. package/dist/oauth/openBrowser.js +22 -5
  33. package/dist/oauth/refreshTokens.js +2 -0
  34. package/dist/oauth/revokeToken.js +5 -1
  35. package/dist/oauth/tokenExchange.js +2 -0
  36. package/dist/oauth/tokenStore.d.ts +52 -3
  37. package/dist/oauth/tokenStore.js +369 -18
  38. package/dist/userAgent.d.ts +12 -0
  39. package/dist/userAgent.js +18 -0
  40. package/docs/architecture.md +201 -0
  41. package/docs/callback-page.md +24 -0
  42. package/docs/callback-server.md +21 -0
  43. package/docs/oauth-flow.md +15 -0
  44. package/package.json +7 -2
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.KeyringTokenStore = exports.STORED_BLOB_VERSION = void 0;
4
+ exports.shouldChunkForKeyring = shouldChunkForKeyring;
4
5
  exports.parseAndMigrateBlob = parseAndMigrateBlob;
6
+ exports.platformKeyringHint = platformKeyringHint;
7
+ exports.chunkBlobForKeyring = chunkBlobForKeyring;
5
8
  const errors_1 = require("./errors");
6
9
  const keyringBinding_1 = require("./keyringBinding");
7
10
  // On macOS: Keychain generic password item with the service name below.
@@ -9,16 +12,45 @@ const keyringBinding_1 = require("./keyringBinding");
9
12
  // Exposed as a human-readable string because these all surface the service
10
13
  // name in OS UIs (Keychain Access, credmgr.exe, seahorse).
11
14
  const SERVICE_NAME = "axe-auth";
12
- // Single keychain entry per machine. The blob it holds is fully
13
- // self-describing (issuerURL, clientId, allowInsecureIssuer, plus the
14
- // tokens), so verbs that don't pass `--server` / `--realm` /
15
- // `--client-id` can resolve their config from the entry.
15
+ // Single keychain entry per machine on macOS / Linux. (Windows splits
16
+ // across `credentials.0`, `credentials.1`, see `CHUNK_LIMIT`
17
+ // below.) The blob it holds is fully self-describing (issuerURL,
18
+ // clientId, allowInsecureIssuer, plus the tokens), so verbs that
19
+ // don't pass `--server` / `--realm` / `--client-id` can resolve their
20
+ // config from the entry.
16
21
  //
17
22
  // Account name is human-readable so users investigating the entry in
18
23
  // macOS Keychain Access (or `secret-tool` on Linux, credmgr on
19
24
  // Windows) can tell what it is. Not versioned: the schema version
20
- // lives inside the blob and migrators handle the upgrade path.
25
+ // lives inside the blob and migrators handle the upgrade path. Note:
26
+ // Windows entries hold base64-encoded JSON rather than the raw JSON
27
+ // macOS / Linux store, so a Windows user inspecting their Credential
28
+ // Manager will see opaque base64; that's a side effect of chunking.
21
29
  const ACCOUNT_NAME = "credentials";
30
+ // Windows Credential Manager caps stored values at 2560 UTF-16 code
31
+ // units, which large OAuth access-token JWTs (many groups/roles
32
+ // claims) routinely exceed. On Windows we work around this by
33
+ // splitting the JSON blob across multiple entries with account names
34
+ // `credentials.0`, `credentials.1`, … . `CHUNK_LIMIT` leaves margin
35
+ // under the platform cap; `MAX_CHUNKS` is a safety bound — we should
36
+ // never get close in practice, even with maximally-claimed tokens.
37
+ //
38
+ // macOS Keychain and Linux libsecret have no comparable limit, so
39
+ // chunking there would just multiply per-entry ACL prompts (each
40
+ // keychain entry is independently lockable on macOS) for no gain.
41
+ // Chunking is therefore Windows-only, gated by `shouldChunkForKeyring`.
42
+ const CHUNK_LIMIT = 2500;
43
+ const MAX_CHUNKS = 32;
44
+ /**
45
+ * Whether `KeyringTokenStore` should split the stored blob across
46
+ * multiple keychain entries on this platform. Windows-only because of
47
+ * Credential Manager's 2560 UTF-16 character per-entry cap. Exported
48
+ * (parameterized for tests) so the chunking path can be exercised
49
+ * deterministically.
50
+ */
51
+ function shouldChunkForKeyring(platform = process.platform) {
52
+ return platform === "win32";
53
+ }
22
54
  /**
23
55
  * Current on-disk blob schema version. Exported so consumers can
24
56
  * display "stored v:N, expected v:M" diagnostics when `load()` returns
@@ -72,7 +104,9 @@ function isLatestBlob(blob) {
72
104
  (b.refreshToken === undefined || typeof b.refreshToken === "string") &&
73
105
  typeof b.issuerURL === "string" &&
74
106
  typeof b.clientId === "string" &&
75
- typeof b.allowInsecureIssuer === "boolean");
107
+ typeof b.allowInsecureIssuer === "boolean" &&
108
+ typeof b.walnutURL === "string" &&
109
+ b.walnutURL.length > 0);
76
110
  }
77
111
  function blobToEntry(blob) {
78
112
  const tokens = {
@@ -86,6 +120,7 @@ function blobToEntry(blob) {
86
120
  issuerURL: blob.issuerURL,
87
121
  clientId: blob.clientId,
88
122
  allowInsecureIssuer: blob.allowInsecureIssuer,
123
+ walnutURL: blob.walnutURL,
89
124
  };
90
125
  }
91
126
  function entryToBlob(entry) {
@@ -96,6 +131,7 @@ function entryToBlob(entry) {
96
131
  issuerURL: entry.issuerURL,
97
132
  clientId: entry.clientId,
98
133
  allowInsecureIssuer: entry.allowInsecureIssuer,
134
+ walnutURL: entry.walnutURL,
99
135
  };
100
136
  if (entry.tokens.refreshToken)
101
137
  blob.refreshToken = entry.tokens.refreshToken;
@@ -149,32 +185,150 @@ function parseAndMigrateBlob(raw, expectedVersion = exports.STORED_BLOB_VERSION,
149
185
  return { ok: true, blob: current };
150
186
  }
151
187
  function wrapKeyringError(op, cause) {
152
- throw new errors_1.OAuthFlowError("KEYRING_UNAVAILABLE", `System keychain ${op} failed. On Linux this usually means no D-Bus Secret Service is running.`, { cause });
188
+ // Pass-through pre-wrapped OAuthFlowErrors so we don't double-wrap
189
+ // our own error type. The most common source today is
190
+ // `defaultEntryFactory` throwing `KEYRING_UNAVAILABLE` when the
191
+ // native binding can't be loaded — relabelling that as another
192
+ // `KEYRING_UNAVAILABLE` with a duplicate message and a possibly
193
+ // misleading platform hint helps nobody.
194
+ if (cause instanceof errors_1.OAuthFlowError) {
195
+ throw cause;
196
+ }
197
+ const causeMessage = cause instanceof Error ? cause.message : String(cause);
198
+ throw new errors_1.OAuthFlowError("KEYRING_UNAVAILABLE", `System keychain ${op} failed: ${causeMessage}. ${platformKeyringHint()}`, { cause });
199
+ }
200
+ /**
201
+ * Returns a per-platform hint appended to keychain error messages so
202
+ * users see actionable guidance for their OS instead of generic or
203
+ * Linux-only advice. Exported (but not re-exported from the package
204
+ * index) so tests can exercise each branch without mocking
205
+ * `process.platform`.
206
+ */
207
+ function platformKeyringHint(platform = process.platform) {
208
+ switch (platform) {
209
+ case "darwin":
210
+ return "On macOS this usually means Keychain Access denied or cancelled the prompt.";
211
+ case "win32":
212
+ return "On Windows this usually means Credential Manager rejected the operation.";
213
+ case "linux":
214
+ return "On Linux this usually means no D-Bus Secret Service is running (e.g. GNOME Keyring or KWallet).";
215
+ default:
216
+ return `Underlying platform: ${platform}.`;
217
+ }
218
+ }
219
+ /**
220
+ * Parses chunk 0's `<N>\n<rest>` header. Returns the chunk count and
221
+ * the data part following the newline, or `null` for any malformed /
222
+ * out-of-range / non-canonically-encoded header. Centralised here
223
+ * (rather than open-coded twice in `#loadChunked` and
224
+ * `#previousChunkN`) so the canonical-encoding contract has one
225
+ * authoritative implementation.
226
+ */
227
+ function parseChunkHeader(first) {
228
+ const newlineIdx = first.indexOf("\n");
229
+ if (newlineIdx <= 0)
230
+ return null;
231
+ const nStr = first.slice(0, newlineIdx);
232
+ const n = parseInt(nStr, 10);
233
+ // Reject non-canonical encodings ("01", " 3", "3abc"). parseInt is
234
+ // permissive about those; we want a single canonical encoding so
235
+ // two different headers can't decode to the same N.
236
+ if (!Number.isInteger(n) || n < 1 || n > MAX_CHUNKS || String(n) !== nStr) {
237
+ return null;
238
+ }
239
+ return { n, rest: first.slice(newlineIdx + 1) };
153
240
  }
154
241
  /**
155
242
  * `TokenStore` backed by the operating system's native keychain via
156
243
  * `@napi-rs/keyring` (macOS Keychain, Windows Credential Manager, Linux
157
- * Secret Service). One entry per machine, keyed by a fixed account
158
- * name; the blob carries its own issuer/client coordinates so verbs
159
- * can recover full config without per-issuer keying.
244
+ * Secret Service). On macOS and Linux the blob lives in a single entry
245
+ * keyed by the fixed `credentials` account name. On Windows the blob
246
+ * is split across `credentials.0`, `credentials.1`, entries to fit
247
+ * under Credential Manager's 2560 UTF-16 character per-entry cap; see
248
+ * `shouldChunkForKeyring`.
249
+ *
250
+ * The blob carries its own issuer/client coordinates so verbs can
251
+ * recover full config without per-issuer keying.
160
252
  */
161
253
  class KeyringTokenStore {
162
- #entry;
254
+ #entryFactory;
255
+ #chunked;
256
+ /**
257
+ * @param entryFactory Injection seam for `@napi-rs/keyring` entries.
258
+ * Defaults to the production lazy-resolved factory; tests pass a
259
+ * recording / faking variant.
260
+ */
163
261
  constructor(entryFactory = keyringBinding_1.defaultEntryFactory) {
164
- this.#entry = entryFactory(SERVICE_NAME, ACCOUNT_NAME);
262
+ this.#entryFactory = entryFactory;
263
+ this.#chunked = shouldChunkForKeyring();
264
+ }
265
+ /**
266
+ * @internal Test seam. Constructs a store with an explicit chunking
267
+ * decision instead of the platform-determined default, so the
268
+ * chunked path can be exercised on macOS/Linux CI and the unchunked
269
+ * path on Windows CI. Production code must use the regular
270
+ * constructor and let `shouldChunkForKeyring()` decide — passing
271
+ * `chunked: true` on macOS would write data that the regular
272
+ * constructor wouldn't be able to read.
273
+ */
274
+ static forTesting(entryFactory, chunked) {
275
+ const store = new KeyringTokenStore(entryFactory);
276
+ store.#chunked = chunked;
277
+ return store;
278
+ }
279
+ #entry(account) {
280
+ return this.#entryFactory(SERVICE_NAME, account);
165
281
  }
166
282
  async save(entry) {
167
- try {
168
- this.#entry.setPassword(JSON.stringify(entryToBlob(entry)));
283
+ const jsonBlob = JSON.stringify(entryToBlob(entry));
284
+ if (this.#chunked) {
285
+ // Encode + chunk OUTSIDE the try/catch so a TOKEN_TOO_LARGE from
286
+ // `chunkBlobForKeyring` surfaces unchanged. The keychain
287
+ // operations stay inside the try and get wrapped as
288
+ // KEYRING_UNAVAILABLE if they fail.
289
+ const encoded = Buffer.from(jsonBlob, "utf8").toString("base64");
290
+ const parts = chunkBlobForKeyring(encoded);
291
+ try {
292
+ this.#saveChunked(parts);
293
+ }
294
+ catch (cause) {
295
+ wrapKeyringError("write", cause);
296
+ }
169
297
  }
170
- catch (cause) {
171
- wrapKeyringError("write", cause);
298
+ else {
299
+ try {
300
+ this.#entry(ACCOUNT_NAME).setPassword(jsonBlob);
301
+ }
302
+ catch (cause) {
303
+ wrapKeyringError("write", cause);
304
+ }
172
305
  }
173
306
  }
174
307
  async load() {
175
308
  let raw;
176
309
  try {
177
- raw = this.#entry.getPassword();
310
+ if (this.#chunked) {
311
+ const result = this.#loadChunked();
312
+ if (result.kind === "present") {
313
+ raw = result.blob;
314
+ }
315
+ else if (result.kind === "empty") {
316
+ // First-time-upgrade fallback: a Windows dev who upgraded
317
+ // across the chunking change has data at the bare
318
+ // `credentials` account but no chunks yet. Read that legacy
319
+ // entry; the next save() migrates it. Note we only fall
320
+ // back when chunked data is *empty* — when chunked data is
321
+ // *corrupt* we surface that directly rather than restoring
322
+ // potentially stale legacy data underneath the corruption.
323
+ raw = this.#entry(ACCOUNT_NAME).getPassword();
324
+ }
325
+ else {
326
+ return { ok: false, reason: "corrupt" };
327
+ }
328
+ }
329
+ else {
330
+ raw = this.#entry(ACCOUNT_NAME).getPassword();
331
+ }
178
332
  }
179
333
  catch (cause) {
180
334
  wrapKeyringError("read", cause);
@@ -188,11 +342,208 @@ class KeyringTokenStore {
188
342
  }
189
343
  async clear() {
190
344
  try {
191
- this.#entry.deletePassword();
345
+ if (this.#chunked) {
346
+ this.#clearChunked();
347
+ }
348
+ else {
349
+ this.#entry(ACCOUNT_NAME).deletePassword();
350
+ }
192
351
  }
193
352
  catch (cause) {
194
353
  wrapKeyringError("delete", cause);
195
354
  }
196
355
  }
356
+ /**
357
+ * Writes `parts` (the output of `chunkBlobForKeyring`) to entries
358
+ * `credentials.0..N-1`.
359
+ *
360
+ * Writes are in **reverse index order** — chunks N-1..1, then chunk
361
+ * 0 with the new header last. Chunk 0's header is what reads use to
362
+ * learn N, so until it's overwritten the previous chunk 0 still
363
+ * references the previous N chunks.
364
+ *
365
+ * Crash recovery is partial, not total. Reverse order helps in one
366
+ * case: when N_new > N_old and the crash happens before chunk 0 is
367
+ * rewritten — writes to indices >= N_old don't disturb old data,
368
+ * the previous chunk 0 still references the previous N chunks, and
369
+ * the prior session survives. The typical refresh case (N_new ==
370
+ * N_old) overwrites chunks 1..N-1 with new data while chunk 0 is
371
+ * still old, so a crash there reads as corrupt and the user
372
+ * re-auths. Reverse order is therefore a marginal improvement over
373
+ * forward order, not a guarantee.
374
+ *
375
+ * Cleanup sweeps `[N_new, N_old)` (bounded by the previous chunk
376
+ * count read from the old chunk 0 header before we overwrite it).
377
+ * For a typical token refresh (same N) this is zero deletes; the
378
+ * full safety sweep up to MAX_CHUNKS only runs as a defensive
379
+ * recovery when the previous N can't be determined. Orphans at
380
+ * indices >= max(N_new, N_old) from interrupted resize-up writes
381
+ * persist until the next `clear()` does the full sweep.
382
+ *
383
+ * Concurrency: this method is not safe to run concurrently against
384
+ * the same OS keychain. Two writers can interleave at chunk
385
+ * boundaries and produce a Frankenstein blob. axe-auth runs as a
386
+ * short-lived CLI so this is unlikely in practice, but a long-lived
387
+ * process refreshing in the background while the CLI is invoked
388
+ * could trip it.
389
+ */
390
+ #saveChunked(parts) {
391
+ // Read previous N before any writes so the cleanup sweep is
392
+ // bounded. If the previous chunk 0 is missing or its header is
393
+ // unparseable we have no upper bound, so fall back to the full
394
+ // safety range as a one-time defensive recovery.
395
+ const previousN = this.#previousChunkN();
396
+ for (let i = parts.length - 1; i >= 1; i--) {
397
+ this.#entry(`${ACCOUNT_NAME}.${i}`).setPassword(parts[i]);
398
+ }
399
+ this.#entry(`${ACCOUNT_NAME}.0`).setPassword(parts[0]);
400
+ // Best-effort sweep: writes have already succeeded, so a sweep
401
+ // failure shouldn't roll back the save. The next save's bounded
402
+ // sweep cleans up anything we miss here. Same reasoning for the
403
+ // legacy delete below.
404
+ const sweepEnd = previousN ?? MAX_CHUNKS;
405
+ for (let i = parts.length; i < sweepEnd; i++) {
406
+ try {
407
+ this.#entry(`${ACCOUNT_NAME}.${i}`).deletePassword();
408
+ }
409
+ catch {
410
+ // Sweep is best-effort; the next save handles leftovers.
411
+ }
412
+ }
413
+ // Clear any pre-chunking single-entry blob from a previous
414
+ // axe-auth release. This is a forever-tax (one extra
415
+ // deletePassword per save even after the migration is done)
416
+ // because we have no per-machine "migration completed" flag;
417
+ // adding one would mean another keychain entry to manage. The
418
+ // cost is one Credential Manager call per refresh — negligible
419
+ // relative to the OAuth round-trip.
420
+ try {
421
+ this.#entry(ACCOUNT_NAME).deletePassword();
422
+ }
423
+ catch {
424
+ // Best-effort; the next save attempts again.
425
+ }
426
+ }
427
+ /**
428
+ * Reads the chunk-count header from `credentials.0` so `#saveChunked`
429
+ * can bound its cleanup sweep. Returns `null` when chunk 0 is
430
+ * missing, when the header is malformed, or when the encoded N is
431
+ * out of range — every "I don't know the previous count" case
432
+ * collapses to a full safety sweep at the call site.
433
+ */
434
+ #previousChunkN() {
435
+ const first = this.#entry(`${ACCOUNT_NAME}.0`).getPassword();
436
+ if (first === null)
437
+ return null;
438
+ return parseChunkHeader(first)?.n ?? null;
439
+ }
440
+ /**
441
+ * Reverse of `#saveChunked`. Returns a discriminated result so the
442
+ * caller can distinguish "no data" from "data is malformed" without
443
+ * reaching for sentinel strings.
444
+ */
445
+ #loadChunked() {
446
+ const first = this.#entry(`${ACCOUNT_NAME}.0`).getPassword();
447
+ if (first === null)
448
+ return { kind: "empty" };
449
+ const header = parseChunkHeader(first);
450
+ if (!header)
451
+ return { kind: "corrupt" };
452
+ const parts = [header.rest];
453
+ for (let i = 1; i < header.n; i++) {
454
+ const part = this.#entry(`${ACCOUNT_NAME}.${i}`).getPassword();
455
+ if (part === null)
456
+ return { kind: "corrupt" };
457
+ parts.push(part);
458
+ }
459
+ // `Buffer.from(_, 'base64')` is permissive — invalid characters
460
+ // are silently dropped rather than throwing. Garbage base64
461
+ // produces garbage UTF-8, which falls through to the upstream
462
+ // JSON.parse and surfaces as `corrupt` from
463
+ // `parseAndMigrateBlob`. So no try/catch is needed here.
464
+ const blob = Buffer.from(parts.join(""), "base64").toString("utf8");
465
+ return { kind: "present", blob };
466
+ }
467
+ #clearChunked() {
468
+ // Sweep the whole safety range rather than break-on-first-missing
469
+ // so chunk holes (from interrupted writes or manual tampering)
470
+ // still get cleaned up. Logout is rare enough that the
471
+ // unconditional sweep cost is irrelevant.
472
+ //
473
+ // Per-entry errors are caught locally so a single throw doesn't
474
+ // strand the remaining chunks (or the legacy entry) in the
475
+ // keychain. After all attempts, we surface the first failure so
476
+ // the user still sees that logout didn't fully complete.
477
+ let firstError = null;
478
+ for (let i = 0; i < MAX_CHUNKS; i++) {
479
+ try {
480
+ this.#entry(`${ACCOUNT_NAME}.${i}`).deletePassword();
481
+ }
482
+ catch (cause) {
483
+ firstError ??= cause;
484
+ }
485
+ }
486
+ // And the pre-chunking single-entry blob, in case a Windows dev
487
+ // had axe-auth installed before chunking shipped.
488
+ try {
489
+ this.#entry(ACCOUNT_NAME).deletePassword();
490
+ }
491
+ catch (cause) {
492
+ firstError ??= cause;
493
+ }
494
+ if (firstError !== null) {
495
+ throw firstError;
496
+ }
497
+ }
197
498
  }
198
499
  exports.KeyringTokenStore = KeyringTokenStore;
500
+ /**
501
+ * Splits `blob` into the N parts that `KeyringTokenStore.#saveChunked`
502
+ * writes to `credentials.0..N-1`. Chunk 0 is prefixed with `<N>\n` so
503
+ * the reader can learn N from a single getPassword call. Each chunk
504
+ * stays under `CHUNK_LIMIT` UTF-16 characters; throws if the blob would
505
+ * require more than `MAX_CHUNKS` chunks. Exported for tests.
506
+ */
507
+ function chunkBlobForKeyring(blob) {
508
+ // N depends on the header length, which depends on N. Solve by
509
+ // iterating until the chunk count stabilises (converges in <= a
510
+ // couple of steps for any realistic blob). The safety counter is
511
+ // belt-and-suspenders against a future tweak (different
512
+ // CHUNK_LIMIT, different header format) accidentally introducing
513
+ // oscillation; an unbounded loop here would hang `axe-auth login`
514
+ // with no error.
515
+ let n = Math.max(1, Math.ceil(blob.length / CHUNK_LIMIT));
516
+ let safety = 0;
517
+ while (true) {
518
+ if (++safety > 8) {
519
+ throw new Error(`chunkBlobForKeyring: chunk count failed to converge after ${safety} iterations (blob length ${blob.length})`);
520
+ }
521
+ const headerLen = String(n).length + 1; // "<N>\n"
522
+ const chunk0Capacity = CHUNK_LIMIT - headerLen;
523
+ if (chunk0Capacity <= 0) {
524
+ throw new Error(`chunkBlobForKeyring: chunk count ${n} leaves no room for data`);
525
+ }
526
+ const remaining = Math.max(0, blob.length - chunk0Capacity);
527
+ const next = 1 + Math.ceil(remaining / CHUNK_LIMIT);
528
+ if (next === n)
529
+ break;
530
+ n = next;
531
+ }
532
+ if (n > MAX_CHUNKS) {
533
+ // Surfaced as a distinct error code (rather than KEYRING_UNAVAILABLE)
534
+ // because the keystore is healthy — the failure is that the IDP's
535
+ // token has too many claims to fit. Wrapping this as a keychain
536
+ // error would attach a misleading "Credential Manager rejected"
537
+ // platform hint via `wrapKeyringError`'s default path.
538
+ throw new errors_1.OAuthFlowError("TOKEN_TOO_LARGE", `OAuth token blob would require ${n} keyring entries (max ${MAX_CHUNKS}). The IDP may be issuing tokens with unusually many claims; talk to the realm administrator.`);
539
+ }
540
+ const headerLen = String(n).length + 1;
541
+ const chunk0Capacity = CHUNK_LIMIT - headerLen;
542
+ const parts = [`${n}\n${blob.slice(0, chunk0Capacity)}`];
543
+ let pos = chunk0Capacity;
544
+ while (pos < blob.length) {
545
+ parts.push(blob.slice(pos, pos + CHUNK_LIMIT));
546
+ pos += CHUNK_LIMIT;
547
+ }
548
+ return parts;
549
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * `User-Agent` header value sent on all outbound requests, per
3
+ * Service Development Standards §4.4.
4
+ *
5
+ * Format: `axe-auth/v<package-version>` (e.g. `axe-auth/v1.0.2`).
6
+ *
7
+ * The npm scope (`@deque/`) is deliberately omitted from the wire format:
8
+ * `@` and `/` are not valid `tchar` per RFC 9110 §5.6.2, so a token like
9
+ * `@deque/axe-auth` would make the User-Agent malformed and risk WAF
10
+ * rejection (e.g. OWASP CRS rule 920330).
11
+ */
12
+ export declare const USER_AGENT: string;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.USER_AGENT = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const node_path_1 = require("node:path");
6
+ const pkg = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, "..", "package.json"), "utf-8"));
7
+ /**
8
+ * `User-Agent` header value sent on all outbound requests, per
9
+ * Service Development Standards §4.4.
10
+ *
11
+ * Format: `axe-auth/v<package-version>` (e.g. `axe-auth/v1.0.2`).
12
+ *
13
+ * The npm scope (`@deque/`) is deliberately omitted from the wire format:
14
+ * `@` and `/` are not valid `tchar` per RFC 9110 §5.6.2, so a token like
15
+ * `@deque/axe-auth` would make the User-Agent malformed and risk WAF
16
+ * rejection (e.g. OWASP CRS rule 920330).
17
+ */
18
+ exports.USER_AGENT = `axe-auth/v${pkg.version}`;