@deque/axe-auth 1.1.0-next.fda76051 → 1.1.0-next.fea0aa8a

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 (54) hide show
  1. package/README.md +58 -17
  2. package/credits.json +53 -0
  3. package/dist/cli/commonArgs.d.ts +35 -0
  4. package/dist/cli/commonArgs.help.d.ts +2 -0
  5. package/dist/cli/commonArgs.help.js +20 -0
  6. package/dist/cli/commonArgs.js +63 -0
  7. package/dist/cli/confirm.d.ts +17 -0
  8. package/dist/cli/confirm.js +53 -0
  9. package/dist/cli/errors.d.ts +13 -0
  10. package/dist/cli/errors.js +30 -0
  11. package/dist/cli/testUtils.d.ts +52 -0
  12. package/dist/cli/testUtils.js +100 -0
  13. package/dist/cli/types.d.ts +39 -0
  14. package/dist/cli/types.js +2 -0
  15. package/dist/commands/login.d.ts +41 -0
  16. package/dist/commands/login.help.d.ts +2 -0
  17. package/dist/commands/login.help.js +41 -0
  18. package/dist/commands/login.js +108 -0
  19. package/dist/commands/logout.d.ts +24 -0
  20. package/dist/commands/logout.help.d.ts +2 -0
  21. package/dist/commands/logout.help.js +38 -0
  22. package/dist/commands/logout.js +68 -0
  23. package/dist/commands/token.d.ts +21 -0
  24. package/dist/commands/token.help.d.ts +2 -0
  25. package/dist/commands/token.help.js +41 -0
  26. package/dist/commands/token.js +40 -0
  27. package/dist/index.js +107 -22
  28. package/dist/oauth/authorizationURL.d.ts +1 -6
  29. package/dist/oauth/authorizationURL.js +2 -6
  30. package/dist/oauth/authorize.d.ts +13 -44
  31. package/dist/oauth/authorize.js +4 -5
  32. package/dist/oauth/discoverOIDC.d.ts +10 -27
  33. package/dist/oauth/discoverOIDC.js +33 -32
  34. package/dist/oauth/discoverSSOConfig.d.ts +37 -0
  35. package/dist/oauth/discoverSSOConfig.js +105 -0
  36. package/dist/oauth/errors.d.ts +2 -0
  37. package/dist/oauth/getValidAccessToken.d.ts +9 -44
  38. package/dist/oauth/getValidAccessToken.js +8 -16
  39. package/dist/oauth/openBrowser.d.ts +14 -3
  40. package/dist/oauth/openBrowser.js +22 -5
  41. package/dist/oauth/refreshTokens.js +2 -3
  42. package/dist/oauth/revokeToken.js +5 -1
  43. package/dist/oauth/tokenExchange.js +2 -0
  44. package/dist/oauth/tokenResponse.d.ts +6 -38
  45. package/dist/oauth/tokenResponse.js +7 -27
  46. package/dist/oauth/tokenStore.d.ts +75 -3
  47. package/dist/oauth/tokenStore.js +394 -32
  48. package/dist/userAgent.d.ts +12 -0
  49. package/dist/userAgent.js +18 -0
  50. package/docs/architecture.md +201 -0
  51. package/docs/callback-page.md +24 -0
  52. package/docs/callback-server.md +21 -0
  53. package/docs/oauth-flow.md +15 -0
  54. package/package.json +13 -5
@@ -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,18 +1,4 @@
1
- /**
2
- * Tokens returned by a successful token-endpoint call (authorization
3
- * code exchange, refresh-token grant, etc.).
4
- *
5
- * `refreshToken` is optional because not all flows return one. On
6
- * authorization-code exchange it's absent if the caller did not
7
- * request `offline_access` (or the provider equivalent); on refresh
8
- * some providers rotate tokens (return a new one) while others don't
9
- * (the caller should keep the existing refresh token).
10
- *
11
- * `grantedScope` reflects the authorization server's `scope` response
12
- * field when present. RFC 6749 §5.1 says `scope` is required in the
13
- * response when the granted set differs from the requested set; many
14
- * servers send it unconditionally.
15
- */
1
+ /** Tokens returned by a successful token-endpoint call. */
16
2
  export interface TokenSet {
17
3
  /** Access token for authenticated API calls. */
18
4
  accessToken: string;
@@ -24,31 +10,13 @@ export interface TokenSet {
24
10
  grantedScope?: string;
25
11
  }
26
12
  /**
27
- * Reads a non-2xx response body and throws
28
- * `OAuthFlowError("TOKEN_EXCHANGE_FAILED", …)` with the OAuth
29
- * `error` / `error_description` surfaced in both message and details
30
- * when present. Shared by both the authorization-code exchange and
31
- * refresh-token paths since the error contract is identical.
32
- *
33
- * @param context Short human-readable description of which call
34
- * failed ("Token exchange", "Token refresh", etc.). Appears in the
35
- * error message.
13
+ * Reads a non-2xx response body and throws `TOKEN_EXCHANGE_FAILED`
14
+ * with the OAuth `error` / `error_description` surfaced when present.
36
15
  */
37
16
  export declare function throwTokenEndpointError(response: Response, context: string): Promise<never>;
38
17
  /**
39
- * Parses a 2xx response body from an RFC 6749 §5.1 token endpoint
40
- * (authorization-code exchange, refresh-token grant, etc.) into a
41
- * `TokenSet`. Validates the required shape (`access_token`,
42
- * `expires_in`, Bearer `token_type`) and converts the relative
43
- * `expires_in` into an absolute `expiresAt` using `issuedAt`.
44
- *
45
- * @param response The HTTP response (must be 2xx; caller handles
46
- * error statuses via `throwTokenEndpointError`).
47
- * @param issuedAt The timestamp captured just before the network
48
- * call. Slightly conservative — the token actually expires
49
- * `expires_in` seconds from when the server issued it, so the
50
- * effective usable window is `expires_in - RTT`, which errs toward
51
- * "expires sooner" rather than "expires later."
52
- * @param endpointURL URL used for error messages.
18
+ * Parses a 2xx response from an RFC 6749 §5.1 token endpoint into a
19
+ * `TokenSet`. `issuedAt` is the timestamp captured just before the
20
+ * network call; the resulting `expiresAt` is conservative by ~RTT.
53
21
  */
54
22
  export declare function parseTokenResponse(response: Response, issuedAt: number, endpointURL: string): Promise<TokenSet>;
@@ -4,10 +4,8 @@ exports.throwTokenEndpointError = throwTokenEndpointError;
4
4
  exports.parseTokenResponse = parseTokenResponse;
5
5
  const errors_1 = require("./errors");
6
6
  const predicates_1 = require("./predicates");
7
- // RFC 6749 §5.1 describes `expires_in` as "the lifetime in seconds"
8
- // without pinning the JSON type, and some providers historically send
9
- // numeric strings. Accept both; reject anything non-positive or
10
- // non-finite.
7
+ // RFC 6749 §5.1 doesn't pin the JSON type and some providers send
8
+ // numeric strings; accept both, reject non-positive or non-finite.
11
9
  function parseExpiresIn(v) {
12
10
  if (typeof v === "number" && Number.isFinite(v) && v > 0)
13
11
  return v;
@@ -37,15 +35,8 @@ function parseErrorBody(body) {
37
35
  };
38
36
  }
39
37
  /**
40
- * Reads a non-2xx response body and throws
41
- * `OAuthFlowError("TOKEN_EXCHANGE_FAILED", …)` with the OAuth
42
- * `error` / `error_description` surfaced in both message and details
43
- * when present. Shared by both the authorization-code exchange and
44
- * refresh-token paths since the error contract is identical.
45
- *
46
- * @param context Short human-readable description of which call
47
- * failed ("Token exchange", "Token refresh", etc.). Appears in the
48
- * error message.
38
+ * Reads a non-2xx response body and throws `TOKEN_EXCHANGE_FAILED`
39
+ * with the OAuth `error` / `error_description` surfaced when present.
49
40
  */
50
41
  async function throwTokenEndpointError(response, context) {
51
42
  const body = await response.text().catch(() => "");
@@ -63,20 +54,9 @@ async function throwTokenEndpointError(response, context) {
63
54
  throw new errors_1.OAuthFlowError("TOKEN_EXCHANGE_FAILED", `${context} failed with HTTP ${response.status}${suffix}`, Object.keys(details).length > 0 ? { details } : undefined);
64
55
  }
65
56
  /**
66
- * Parses a 2xx response body from an RFC 6749 §5.1 token endpoint
67
- * (authorization-code exchange, refresh-token grant, etc.) into a
68
- * `TokenSet`. Validates the required shape (`access_token`,
69
- * `expires_in`, Bearer `token_type`) and converts the relative
70
- * `expires_in` into an absolute `expiresAt` using `issuedAt`.
71
- *
72
- * @param response The HTTP response (must be 2xx; caller handles
73
- * error statuses via `throwTokenEndpointError`).
74
- * @param issuedAt The timestamp captured just before the network
75
- * call. Slightly conservative — the token actually expires
76
- * `expires_in` seconds from when the server issued it, so the
77
- * effective usable window is `expires_in - RTT`, which errs toward
78
- * "expires sooner" rather than "expires later."
79
- * @param endpointURL URL used for error messages.
57
+ * Parses a 2xx response from an RFC 6749 §5.1 token endpoint into a
58
+ * `TokenSet`. `issuedAt` is the timestamp captured just before the
59
+ * network call; the resulting `expiresAt` is conservative by ~RTT.
80
60
  */
81
61
  async function parseTokenResponse(response, issuedAt, endpointURL) {
82
62
  let parsed;
@@ -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[];