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

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 +75 -3
  37. package/dist/oauth/tokenStore.js +405 -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
@@ -7,13 +7,24 @@ export interface OpenBrowserOptions {
7
7
  platform?: NodeJS.Platform;
8
8
  /** Override for `child_process.spawn`. Used by tests. */
9
9
  spawnFn?: SpawnFn;
10
+ /**
11
+ * Override for `process.env.BROWSER`. The de-facto convention shared
12
+ * with `xdg-open` and Python's `webbrowser`: when set, it names the
13
+ * command to invoke instead of the platform default. Parsed shlex-style
14
+ * (POSIX shell tokenization) so values like `firefox --new-window` or
15
+ * `/path/with\ spaces/firefox` work as expected. An empty or missing
16
+ * value falls back to the platform default.
17
+ */
18
+ browserEnv?: string;
10
19
  }
11
20
  /**
12
21
  * Launches the system browser at `url` in a detached child process.
13
- * Returns synchronously once the child is spawned completion of the
14
- * browser load is intentionally not awaited.
22
+ * Honors `$BROWSER` when set, falling back to the platform default
23
+ * (`open` / `xdg-open` / `cmd start`). Returns synchronously once the
24
+ * child is spawned — completion of the browser load is intentionally
25
+ * not awaited.
15
26
  *
16
27
  * @param url Absolute URL to open.
17
- * @param options Platform/spawn overrides; only exposed for tests.
28
+ * @param options Platform/spawn/env overrides; only exposed for tests.
18
29
  */
19
30
  export declare function openBrowser(url: string, options?: OpenBrowserOptions): void;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.openBrowser = openBrowser;
4
4
  const node_child_process_1 = require("node:child_process");
5
+ const shlex_1 = require("shlex");
5
6
  const errors_1 = require("./errors");
6
7
  // On Windows `start` is a cmd.exe builtin, not a standalone binary.
7
8
  // The empty `""` pair is a positional placeholder for the window
@@ -26,7 +27,11 @@ function windowsCommand(url) {
26
27
  args: ["/c", "start", '""', url.replace(/[&|^<>"%\r\n]/g, (c) => `^${c}`)],
27
28
  };
28
29
  }
29
- function browserCommand(platform, url) {
30
+ function browserCommand(platform, url, browserOverride) {
31
+ if (browserOverride && browserOverride.length > 0) {
32
+ const [command, ...extraArgs] = browserOverride;
33
+ return { command, args: [...extraArgs, url] };
34
+ }
30
35
  switch (platform) {
31
36
  case "darwin":
32
37
  return { command: "open", args: [url] };
@@ -47,16 +52,28 @@ function browserCommand(platform, url) {
47
52
  }
48
53
  /**
49
54
  * Launches the system browser at `url` in a detached child process.
50
- * Returns synchronously once the child is spawned completion of the
51
- * browser load is intentionally not awaited.
55
+ * Honors `$BROWSER` when set, falling back to the platform default
56
+ * (`open` / `xdg-open` / `cmd start`). Returns synchronously once the
57
+ * child is spawned — completion of the browser load is intentionally
58
+ * not awaited.
52
59
  *
53
60
  * @param url Absolute URL to open.
54
- * @param options Platform/spawn overrides; only exposed for tests.
61
+ * @param options Platform/spawn/env overrides; only exposed for tests.
55
62
  */
56
63
  function openBrowser(url, options = {}) {
57
64
  const platform = options.platform ?? process.platform;
58
65
  const spawnFn = options.spawnFn ?? node_child_process_1.spawn;
59
- const { command, args } = browserCommand(platform, url);
66
+ const browserEnv = options.browserEnv ?? process.env.BROWSER;
67
+ let browserOverride;
68
+ if (browserEnv && browserEnv.length > 0) {
69
+ try {
70
+ browserOverride = (0, shlex_1.split)(browserEnv);
71
+ }
72
+ catch (cause) {
73
+ throw new errors_1.OAuthFlowError("BROWSER_LAUNCH_FAILED", `Failed to parse $BROWSER (${browserEnv}). Open this URL manually:\n${url}`, { cause });
74
+ }
75
+ }
76
+ const { command, args } = browserCommand(platform, url, browserOverride);
60
77
  let child;
61
78
  try {
62
79
  child = spawnFn(command, args, {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.refreshTokens = refreshTokens;
4
4
  const errors_1 = require("./errors");
5
5
  const tokenResponse_1 = require("./tokenResponse");
6
+ const userAgent_1 = require("../userAgent");
6
7
  /**
7
8
  * Exchanges a refresh token for a fresh access token via RFC 6749 §6.
8
9
  *
@@ -39,6 +40,7 @@ async function refreshTokens(options) {
39
40
  headers: {
40
41
  "Content-Type": "application/x-www-form-urlencoded",
41
42
  Accept: "application/json",
43
+ "User-Agent": userAgent_1.USER_AGENT,
42
44
  },
43
45
  body,
44
46
  signal: options.signal,
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.revokeRefreshToken = revokeRefreshToken;
4
+ const userAgent_1 = require("../userAgent");
4
5
  /**
5
6
  * Revokes a refresh token via RFC 7009. Servers SHOULD return 200
6
7
  * regardless of whether the token was valid (the spec doesn't want
@@ -27,7 +28,10 @@ async function revokeRefreshToken(options) {
27
28
  try {
28
29
  response = await fetch(options.revocationEndpoint, {
29
30
  method: "POST",
30
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
31
+ headers: {
32
+ "Content-Type": "application/x-www-form-urlencoded",
33
+ "User-Agent": userAgent_1.USER_AGENT,
34
+ },
31
35
  body,
32
36
  signal: options.signal,
33
37
  });
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.exchangeCodeForTokens = exchangeCodeForTokens;
4
4
  const errors_1 = require("./errors");
5
5
  const tokenResponse_1 = require("./tokenResponse");
6
+ const userAgent_1 = require("../userAgent");
6
7
  /**
7
8
  * Exchanges an authorization code for a `TokenSet` via the
8
9
  * authorization server's token endpoint (RFC 6749 §4.1.3 + RFC 7636
@@ -27,6 +28,7 @@ async function exchangeCodeForTokens(options) {
27
28
  headers: {
28
29
  "Content-Type": "application/x-www-form-urlencoded",
29
30
  Accept: "application/json",
31
+ "User-Agent": userAgent_1.USER_AGENT,
30
32
  },
31
33
  body,
32
34
  signal: options.signal,
@@ -1,5 +1,13 @@
1
1
  import { type KeyringEntryFactory } from "./keyringBinding";
2
2
  import type { TokenSet } from "./tokenResponse";
3
+ /**
4
+ * Whether `KeyringTokenStore` should split the stored blob across
5
+ * multiple keychain entries on this platform. Windows-only because of
6
+ * Credential Manager's 2560 UTF-16 character per-entry cap. Exported
7
+ * (parameterized for tests) so the chunking path can be exercised
8
+ * deterministically.
9
+ */
10
+ export declare function shouldChunkForKeyring(platform?: NodeJS.Platform): boolean;
3
11
  /**
4
12
  * Current on-disk blob schema version. Exported so consumers can
5
13
  * display "stored v:N, expected v:M" diagnostics when `load()` returns
@@ -21,6 +29,11 @@ export interface StoredEntry {
21
29
  clientId: string;
22
30
  /** Whether the original login allowed a non-loopback http issuer. */
23
31
  allowInsecureIssuer: boolean;
32
+ /**
33
+ * Originating axe server (walnut) URL the user supplied (or the
34
+ * SaaS prod default) at login.
35
+ */
36
+ walnutURL: string;
24
37
  }
25
38
  /**
26
39
  * Outcome of a `TokenStore.load()` call.
@@ -95,17 +108,76 @@ export type BlobChainResult = {
95
108
  * and `MIGRATORS` and applies the latest-shape check on top.
96
109
  */
97
110
  export declare function parseAndMigrateBlob(raw: string | null, expectedVersion?: number, migrators?: ReadonlyMap<number, (old: unknown) => unknown | null>): BlobChainResult;
111
+ /**
112
+ * Builds the user-facing keychain error message. Platform is a
113
+ * parameter (defaulting to `process.platform`) so tests can drive each
114
+ * branch without mocking the runtime; mirrors the pattern in
115
+ * `platformKeyringHint`.
116
+ *
117
+ * The Windows-specific size-limit message is only used when the
118
+ * underlying error matches the binding's "longer than the platform
119
+ * limit" wording AND the runtime is win32 — that combination is the
120
+ * only way the size cap actually manifests in practice. On other
121
+ * platforms (or for any other binding error) we fall back to the
122
+ * generic per-platform hint.
123
+ */
124
+ export declare function keyringErrorMessage(op: string, cause: unknown, platform?: NodeJS.Platform): string;
125
+ /**
126
+ * Detects the `@napi-rs/keyring` error string for "value too large".
127
+ * In practice only Windows Credential Manager triggers this — its
128
+ * stored values are capped at 2560 UTF-16 chars; macOS Keychain and
129
+ * Linux libsecret have no comparable limit. Exported (but not
130
+ * re-exported from the package index) so tests can exercise the
131
+ * detector independently of the wrap path.
132
+ */
133
+ export declare function isKeyringSizeError(cause: unknown): boolean;
134
+ /**
135
+ * Returns a per-platform hint appended to keychain error messages so
136
+ * users see actionable guidance for their OS instead of generic or
137
+ * Linux-only advice. Exported (but not re-exported from the package
138
+ * index) so tests can exercise each branch without mocking
139
+ * `process.platform`.
140
+ */
141
+ export declare function platformKeyringHint(platform?: NodeJS.Platform): string;
98
142
  /**
99
143
  * `TokenStore` backed by the operating system's native keychain via
100
144
  * `@napi-rs/keyring` (macOS Keychain, Windows Credential Manager, Linux
101
- * Secret Service). One entry per machine, keyed by a fixed account
102
- * name; the blob carries its own issuer/client coordinates so verbs
103
- * can recover full config without per-issuer keying.
145
+ * Secret Service). On macOS and Linux the blob lives in a single entry
146
+ * keyed by the fixed `credentials` account name. On Windows the blob
147
+ * is split across `credentials.0`, `credentials.1`, entries to fit
148
+ * under Credential Manager's 2560 UTF-16 character per-entry cap; see
149
+ * `shouldChunkForKeyring`.
150
+ *
151
+ * The blob carries its own issuer/client coordinates so verbs can
152
+ * recover full config without per-issuer keying.
104
153
  */
105
154
  export declare class KeyringTokenStore implements TokenStore {
106
155
  #private;
156
+ /**
157
+ * @param entryFactory Injection seam for `@napi-rs/keyring` entries.
158
+ * Defaults to the production lazy-resolved factory; tests pass a
159
+ * recording / faking variant.
160
+ */
107
161
  constructor(entryFactory?: KeyringEntryFactory);
162
+ /**
163
+ * @internal Test seam. Constructs a store with an explicit chunking
164
+ * decision instead of the platform-determined default, so the
165
+ * chunked path can be exercised on macOS/Linux CI and the unchunked
166
+ * path on Windows CI. Production code must use the regular
167
+ * constructor and let `shouldChunkForKeyring()` decide — passing
168
+ * `chunked: true` on macOS would write data that the regular
169
+ * constructor wouldn't be able to read.
170
+ */
171
+ static forTesting(entryFactory: KeyringEntryFactory, chunked: boolean): KeyringTokenStore;
108
172
  save(entry: StoredEntry): Promise<void>;
109
173
  load(): Promise<LoadResult>;
110
174
  clear(): Promise<void>;
111
175
  }
176
+ /**
177
+ * Splits `blob` into the N parts that `KeyringTokenStore.#saveChunked`
178
+ * writes to `credentials.0..N-1`. Chunk 0 is prefixed with `<N>\n` so
179
+ * the reader can learn N from a single getPassword call. Each chunk
180
+ * stays under `CHUNK_LIMIT` UTF-16 characters; throws if the blob would
181
+ * require more than `MAX_CHUNKS` chunks. Exported for tests.
182
+ */
183
+ export declare function chunkBlobForKeyring(blob: string): string[];