@deque/axe-auth 0.0.1-skeleton → 1.1.0-next.0269a5dd

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 (78) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +85 -1
  3. package/credits.json +42 -0
  4. package/dist/cli/commonArgs.d.ts +82 -0
  5. package/dist/cli/commonArgs.help.d.ts +2 -0
  6. package/dist/cli/commonArgs.help.js +20 -0
  7. package/dist/cli/commonArgs.js +90 -0
  8. package/dist/cli/confirm.d.ts +17 -0
  9. package/dist/cli/confirm.js +56 -0
  10. package/dist/cli/errors.d.ts +20 -0
  11. package/dist/cli/errors.js +37 -0
  12. package/dist/cli/testUtils.d.ts +52 -0
  13. package/dist/cli/testUtils.js +100 -0
  14. package/dist/cli/types.d.ts +79 -0
  15. package/dist/cli/types.js +2 -0
  16. package/dist/commands/login.d.ts +44 -0
  17. package/dist/commands/login.help.d.ts +2 -0
  18. package/dist/commands/login.help.js +41 -0
  19. package/dist/commands/login.js +117 -0
  20. package/dist/commands/logout.d.ts +24 -0
  21. package/dist/commands/logout.help.d.ts +2 -0
  22. package/dist/commands/logout.help.js +38 -0
  23. package/dist/commands/logout.js +70 -0
  24. package/dist/commands/token.d.ts +21 -0
  25. package/dist/commands/token.help.d.ts +2 -0
  26. package/dist/commands/token.help.js +41 -0
  27. package/dist/commands/token.js +44 -0
  28. package/dist/index.d.ts +2 -0
  29. package/dist/index.js +139 -0
  30. package/dist/oauth/authorizationURL.d.ts +29 -0
  31. package/dist/oauth/authorizationURL.js +52 -0
  32. package/dist/oauth/authorize.d.ts +91 -0
  33. package/dist/oauth/authorize.js +119 -0
  34. package/dist/oauth/callbackServer.d.ts +23 -0
  35. package/dist/oauth/callbackServer.js +234 -0
  36. package/dist/oauth/discoverOIDC.d.ts +50 -0
  37. package/dist/oauth/discoverOIDC.js +173 -0
  38. package/dist/oauth/discoverSSOConfig.d.ts +47 -0
  39. package/dist/oauth/discoverSSOConfig.js +105 -0
  40. package/dist/oauth/errors.d.ts +75 -0
  41. package/dist/oauth/errors.js +48 -0
  42. package/dist/oauth/getValidAccessToken.d.ts +89 -0
  43. package/dist/oauth/getValidAccessToken.js +140 -0
  44. package/dist/oauth/index.d.ts +16 -0
  45. package/dist/oauth/index.js +19 -0
  46. package/dist/oauth/issuerURL.d.ts +22 -0
  47. package/dist/oauth/issuerURL.js +38 -0
  48. package/dist/oauth/keyringBinding.d.ts +22 -0
  49. package/dist/oauth/keyringBinding.js +41 -0
  50. package/dist/oauth/logo.generated.d.ts +1 -0
  51. package/dist/oauth/logo.generated.js +7 -0
  52. package/dist/oauth/openBrowser.d.ts +19 -0
  53. package/dist/oauth/openBrowser.js +78 -0
  54. package/dist/oauth/pkce.d.ts +17 -0
  55. package/dist/oauth/pkce.js +43 -0
  56. package/dist/oauth/predicates.d.ts +7 -0
  57. package/dist/oauth/predicates.js +15 -0
  58. package/dist/oauth/refreshTokens.d.ts +30 -0
  59. package/dist/oauth/refreshTokens.js +63 -0
  60. package/dist/oauth/renderHtml.d.ts +9 -0
  61. package/dist/oauth/renderHtml.js +60 -0
  62. package/dist/oauth/revokeToken.d.ts +28 -0
  63. package/dist/oauth/revokeToken.js +63 -0
  64. package/dist/oauth/testUtils.d.ts +35 -0
  65. package/dist/oauth/testUtils.js +61 -0
  66. package/dist/oauth/tokenExchange.d.ts +26 -0
  67. package/dist/oauth/tokenExchange.js +44 -0
  68. package/dist/oauth/tokenResponse.d.ts +54 -0
  69. package/dist/oauth/tokenResponse.js +121 -0
  70. package/dist/oauth/tokenStore.d.ts +124 -0
  71. package/dist/oauth/tokenStore.js +223 -0
  72. package/dist/userAgent.d.ts +12 -0
  73. package/dist/userAgent.js +18 -0
  74. package/docs/architecture.md +201 -0
  75. package/docs/callback-page.md +24 -0
  76. package/docs/callback-server.md +21 -0
  77. package/docs/oauth-flow.md +15 -0
  78. package/package.json +40 -5
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throwTokenEndpointError = throwTokenEndpointError;
4
+ exports.parseTokenResponse = parseTokenResponse;
5
+ const errors_1 = require("./errors");
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.
11
+ function parseExpiresIn(v) {
12
+ if (typeof v === "number" && Number.isFinite(v) && v > 0)
13
+ return v;
14
+ if (typeof v === "string") {
15
+ const n = Number(v);
16
+ if (Number.isFinite(n) && n > 0)
17
+ return n;
18
+ }
19
+ return null;
20
+ }
21
+ function parseErrorBody(body) {
22
+ let parsed;
23
+ try {
24
+ parsed = JSON.parse(body);
25
+ }
26
+ catch {
27
+ return {};
28
+ }
29
+ if (parsed === null || typeof parsed !== "object")
30
+ return {};
31
+ const raw = parsed;
32
+ return {
33
+ error: (0, predicates_1.isNonEmptyString)(raw.error) ? raw.error : undefined,
34
+ description: (0, predicates_1.isNonEmptyString)(raw.error_description)
35
+ ? raw.error_description
36
+ : undefined,
37
+ };
38
+ }
39
+ /**
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.
49
+ */
50
+ async function throwTokenEndpointError(response, context) {
51
+ const body = await response.text().catch(() => "");
52
+ const { error, description } = parseErrorBody(body);
53
+ const suffix = error
54
+ ? description
55
+ ? `: ${error}: ${description}`
56
+ : `: ${error}`
57
+ : "";
58
+ const details = {};
59
+ if (error)
60
+ details.error = error;
61
+ if (description)
62
+ details.error_description = description;
63
+ throw new errors_1.OAuthFlowError("TOKEN_EXCHANGE_FAILED", `${context} failed with HTTP ${response.status}${suffix}`, Object.keys(details).length > 0 ? { details } : undefined);
64
+ }
65
+ /**
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.
80
+ */
81
+ async function parseTokenResponse(response, issuedAt, endpointURL) {
82
+ let parsed;
83
+ try {
84
+ parsed = await response.json();
85
+ }
86
+ catch (cause) {
87
+ throw new errors_1.OAuthFlowError("TOKEN_EXCHANGE_FAILED", `Token endpoint at ${endpointURL} returned a non-JSON response`, { cause });
88
+ }
89
+ if (parsed === null || typeof parsed !== "object") {
90
+ throw new errors_1.OAuthFlowError("TOKEN_EXCHANGE_FAILED", `Token endpoint at ${endpointURL} returned a non-object response`);
91
+ }
92
+ const raw = parsed;
93
+ if (!(0, predicates_1.isNonEmptyString)(raw.access_token)) {
94
+ throw new errors_1.OAuthFlowError("TOKEN_EXCHANGE_FAILED", `Token response missing 'access_token'`);
95
+ }
96
+ const expiresIn = parseExpiresIn(raw.expires_in);
97
+ if (expiresIn === null) {
98
+ throw new errors_1.OAuthFlowError("TOKEN_EXCHANGE_FAILED", `Token response missing or has invalid 'expires_in'`);
99
+ }
100
+ // RFC 6749 §5.1: token_type is REQUIRED. We only speak Bearer;
101
+ // DPoP / MAC / other proof-of-possession types need request-side
102
+ // support we don't implement, and silently treating them as Bearer
103
+ // would send tokens in the wrong header with unclear semantics.
104
+ if (!(0, predicates_1.isNonEmptyString)(raw.token_type)) {
105
+ throw new errors_1.OAuthFlowError("TOKEN_EXCHANGE_FAILED", `Token response missing required 'token_type'`);
106
+ }
107
+ if (raw.token_type.toLowerCase() !== "bearer") {
108
+ throw new errors_1.OAuthFlowError("TOKEN_EXCHANGE_FAILED", `Unsupported token_type '${raw.token_type}'; this library only handles Bearer.`);
109
+ }
110
+ const tokens = {
111
+ accessToken: raw.access_token,
112
+ expiresAt: issuedAt + expiresIn * 1000,
113
+ };
114
+ if ((0, predicates_1.isNonEmptyString)(raw.refresh_token)) {
115
+ tokens.refreshToken = raw.refresh_token;
116
+ }
117
+ if ((0, predicates_1.isNonEmptyString)(raw.scope)) {
118
+ tokens.grantedScope = raw.scope;
119
+ }
120
+ return tokens;
121
+ }
@@ -0,0 +1,124 @@
1
+ import { type KeyringEntryFactory } from "./keyringBinding";
2
+ import type { TokenSet } from "./tokenResponse";
3
+ /**
4
+ * Current on-disk blob schema version. Exported so consumers can
5
+ * display "stored v:N, expected v:M" diagnostics when `load()` returns
6
+ * a `version-mismatch` result.
7
+ */
8
+ export declare const STORED_BLOB_VERSION = 1;
9
+ /**
10
+ * What `KeyringTokenStore` persists: the OAuth tokens plus the
11
+ * issuer/client coordinates they were minted against. Carrying the
12
+ * coordinates inside the entry means a verb can recover its full
13
+ * config from the keychain alone, with no separate "default issuer"
14
+ * pointer.
15
+ */
16
+ export interface StoredEntry {
17
+ tokens: TokenSet;
18
+ /** OIDC issuer URL the tokens were minted against. */
19
+ issuerURL: string;
20
+ /** OAuth client ID used at login. */
21
+ clientId: string;
22
+ /** Whether the original login allowed a non-loopback http issuer. */
23
+ allowInsecureIssuer: boolean;
24
+ /**
25
+ * Originating axe server (walnut) URL the user supplied (or the
26
+ * SaaS prod default) at login.
27
+ */
28
+ walnutURL: string;
29
+ }
30
+ /**
31
+ * Outcome of a `TokenStore.load()` call.
32
+ *
33
+ * Note on downgrades: the migrator chain only walks *forward*. A user
34
+ * who downgrades `axe-auth` to a release that predates a schema bump
35
+ * will see `version-mismatch` on any blob written by the newer
36
+ * release, even if the change was strictly additive. That is the safe
37
+ * default for a credentials blob — the older version cannot vouch for
38
+ * the meaning of fields it has never seen. Callers hitting this case
39
+ * should treat it as "re-authenticate" rather than attempting to
40
+ * parse an unknown future shape.
41
+ */
42
+ export type LoadResult = {
43
+ ok: true;
44
+ entry: StoredEntry;
45
+ } | {
46
+ ok: false;
47
+ reason: "empty";
48
+ } | {
49
+ ok: false;
50
+ reason: "corrupt";
51
+ } | {
52
+ ok: false;
53
+ reason: "version-mismatch";
54
+ storedVersion: number;
55
+ };
56
+ /** Persistence layer for an OAuth `StoredEntry`. */
57
+ export interface TokenStore {
58
+ /** Write-through save. Replaces any previously stored entry. */
59
+ save(entry: StoredEntry): Promise<void>;
60
+ /**
61
+ * Reads the stored entry and returns a structured result.
62
+ *
63
+ * Callers should branch on `result.ok` first. When `ok` is `false`,
64
+ * `reason` tells them *why* there is no usable entry: `empty`
65
+ * (nothing stored), `corrupt` (unparseable or shape-invalid), or
66
+ * `version-mismatch` (stored under a schema we cannot migrate from).
67
+ * The library does not emit output on these cases — surfacing them
68
+ * to the user is the caller's responsibility.
69
+ */
70
+ load(): Promise<LoadResult>;
71
+ /** Removes any stored entry. No-op if none is present. */
72
+ clear(): Promise<void>;
73
+ }
74
+ /**
75
+ * Outcome of `parseAndMigrateBlob`: same set of failure reasons as
76
+ * `LoadResult`, but on success carries the post-migration blob as an
77
+ * unknown payload. The caller is responsible for shape-validating
78
+ * that payload against the latest schema.
79
+ */
80
+ export type BlobChainResult = {
81
+ ok: true;
82
+ blob: unknown;
83
+ } | {
84
+ ok: false;
85
+ reason: "empty";
86
+ } | {
87
+ ok: false;
88
+ reason: "corrupt";
89
+ } | {
90
+ ok: false;
91
+ reason: "version-mismatch";
92
+ storedVersion: number;
93
+ };
94
+ /**
95
+ * JSON-parses the raw keychain password and walks the migrator chain
96
+ * until it reaches `expectedVersion`. Exported with `expectedVersion`
97
+ * and `migrators` parameters only for testing the chain mechanics
98
+ * against synthetic versions / migrators; production callers use
99
+ * `KeyringTokenStore.load()`, which feeds in `STORED_BLOB_VERSION`
100
+ * and `MIGRATORS` and applies the latest-shape check on top.
101
+ */
102
+ export declare function parseAndMigrateBlob(raw: string | null, expectedVersion?: number, migrators?: ReadonlyMap<number, (old: unknown) => unknown | null>): BlobChainResult;
103
+ /**
104
+ * Returns a per-platform hint appended to keychain error messages so
105
+ * users see actionable guidance for their OS instead of generic or
106
+ * Linux-only advice. Exported (but not re-exported from the package
107
+ * index) so tests can exercise each branch without mocking
108
+ * `process.platform`.
109
+ */
110
+ export declare function platformKeyringHint(platform?: NodeJS.Platform): string;
111
+ /**
112
+ * `TokenStore` backed by the operating system's native keychain via
113
+ * `@napi-rs/keyring` (macOS Keychain, Windows Credential Manager, Linux
114
+ * Secret Service). One entry per machine, keyed by a fixed account
115
+ * name; the blob carries its own issuer/client coordinates so verbs
116
+ * can recover full config without per-issuer keying.
117
+ */
118
+ export declare class KeyringTokenStore implements TokenStore {
119
+ #private;
120
+ constructor(entryFactory?: KeyringEntryFactory);
121
+ save(entry: StoredEntry): Promise<void>;
122
+ load(): Promise<LoadResult>;
123
+ clear(): Promise<void>;
124
+ }
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.KeyringTokenStore = exports.STORED_BLOB_VERSION = void 0;
4
+ exports.parseAndMigrateBlob = parseAndMigrateBlob;
5
+ exports.platformKeyringHint = platformKeyringHint;
6
+ const errors_1 = require("./errors");
7
+ const keyringBinding_1 = require("./keyringBinding");
8
+ // On macOS: Keychain generic password item with the service name below.
9
+ // On Windows: Credential Manager entry. On Linux: Secret Service / libsecret.
10
+ // Exposed as a human-readable string because these all surface the service
11
+ // name in OS UIs (Keychain Access, credmgr.exe, seahorse).
12
+ const SERVICE_NAME = "axe-auth";
13
+ // Single keychain entry per machine. The blob it holds is fully
14
+ // self-describing (issuerURL, clientId, allowInsecureIssuer, plus the
15
+ // tokens), so verbs that don't pass `--server` / `--realm` /
16
+ // `--client-id` can resolve their config from the entry.
17
+ //
18
+ // Account name is human-readable so users investigating the entry in
19
+ // macOS Keychain Access (or `secret-tool` on Linux, credmgr on
20
+ // Windows) can tell what it is. Not versioned: the schema version
21
+ // lives inside the blob and migrators handle the upgrade path.
22
+ const ACCOUNT_NAME = "credentials";
23
+ /**
24
+ * Current on-disk blob schema version. Exported so consumers can
25
+ * display "stored v:N, expected v:M" diagnostics when `load()` returns
26
+ * a `version-mismatch` result.
27
+ */
28
+ exports.STORED_BLOB_VERSION = 1;
29
+ /**
30
+ * Migrators upgrade an older blob to the next version up. Walked by
31
+ * `load()` until the stored blob reaches `STORED_BLOB_VERSION`.
32
+ *
33
+ * A migrator returns `null` when the bump cannot be inferred from the
34
+ * old shape (e.g. a new required field with no derivable default); the
35
+ * caller then sees `{ ok: false, reason: "version-mismatch" }` and
36
+ * decides whether to re-auth, prompt, or preserve the old blob.
37
+ *
38
+ * Each migrator is responsible for taking `vN` → `vN+1`. To skip a
39
+ * version deliberately, register a migrator that returns `null` for
40
+ * that `fromVersion`.
41
+ */
42
+ const MIGRATORS = new Map([
43
+ // [1, (v1) => migrateV1ToV2(v1 as StoredBlobV1)],
44
+ ]);
45
+ // Sanity-check the migrator map at module load. Every key must be
46
+ // strictly less than `STORED_BLOB_VERSION` — the chain only walks
47
+ // forward, so a leftover migrator at the current (or future) version
48
+ // would either be unreachable or confuse the loop. Fail-fast so a
49
+ // dev forgetting to remove a stale entry during a version bump
50
+ // notices before shipping.
51
+ for (const fromVersion of MIGRATORS.keys()) {
52
+ if (fromVersion >= exports.STORED_BLOB_VERSION) {
53
+ throw new Error(`MIGRATORS contains a key (v${fromVersion}) that is not strictly less than STORED_BLOB_VERSION (${exports.STORED_BLOB_VERSION}). The chain only walks forward; remove stale migrators when bumping the schema version.`);
54
+ }
55
+ }
56
+ function getStoredVersion(blob) {
57
+ if (blob === null || typeof blob !== "object")
58
+ return null;
59
+ const v = blob.v;
60
+ return typeof v === "number" && Number.isInteger(v) && v > 0 ? v : null;
61
+ }
62
+ function isLatestBlob(blob) {
63
+ if (blob === null || typeof blob !== "object")
64
+ return false;
65
+ const b = blob;
66
+ return (b.v === exports.STORED_BLOB_VERSION &&
67
+ // Empty access token is treated as corrupt rather than a usable
68
+ // credential. `axe-auth token` printing an empty line and exiting
69
+ // 0 would look like success and silently break downstream.
70
+ typeof b.accessToken === "string" &&
71
+ b.accessToken.length > 0 &&
72
+ typeof b.expiresAt === "number" &&
73
+ (b.refreshToken === undefined || typeof b.refreshToken === "string") &&
74
+ typeof b.issuerURL === "string" &&
75
+ typeof b.clientId === "string" &&
76
+ typeof b.allowInsecureIssuer === "boolean" &&
77
+ typeof b.walnutURL === "string" &&
78
+ b.walnutURL.length > 0);
79
+ }
80
+ function blobToEntry(blob) {
81
+ const tokens = {
82
+ accessToken: blob.accessToken,
83
+ expiresAt: blob.expiresAt,
84
+ };
85
+ if (blob.refreshToken)
86
+ tokens.refreshToken = blob.refreshToken;
87
+ return {
88
+ tokens,
89
+ issuerURL: blob.issuerURL,
90
+ clientId: blob.clientId,
91
+ allowInsecureIssuer: blob.allowInsecureIssuer,
92
+ walnutURL: blob.walnutURL,
93
+ };
94
+ }
95
+ function entryToBlob(entry) {
96
+ const blob = {
97
+ v: exports.STORED_BLOB_VERSION,
98
+ accessToken: entry.tokens.accessToken,
99
+ expiresAt: entry.tokens.expiresAt,
100
+ issuerURL: entry.issuerURL,
101
+ clientId: entry.clientId,
102
+ allowInsecureIssuer: entry.allowInsecureIssuer,
103
+ walnutURL: entry.walnutURL,
104
+ };
105
+ if (entry.tokens.refreshToken)
106
+ blob.refreshToken = entry.tokens.refreshToken;
107
+ return blob;
108
+ }
109
+ /**
110
+ * JSON-parses the raw keychain password and walks the migrator chain
111
+ * until it reaches `expectedVersion`. Exported with `expectedVersion`
112
+ * and `migrators` parameters only for testing the chain mechanics
113
+ * against synthetic versions / migrators; production callers use
114
+ * `KeyringTokenStore.load()`, which feeds in `STORED_BLOB_VERSION`
115
+ * and `MIGRATORS` and applies the latest-shape check on top.
116
+ */
117
+ function parseAndMigrateBlob(raw, expectedVersion = exports.STORED_BLOB_VERSION, migrators = MIGRATORS) {
118
+ if (raw === null)
119
+ return { ok: false, reason: "empty" };
120
+ let parsed;
121
+ try {
122
+ parsed = JSON.parse(raw);
123
+ }
124
+ catch {
125
+ return { ok: false, reason: "corrupt" };
126
+ }
127
+ const storedVersion = getStoredVersion(parsed);
128
+ if (storedVersion === null)
129
+ return { ok: false, reason: "corrupt" };
130
+ // Walk the migrator chain until we reach the expected version. A
131
+ // missing or null-returning migrator means the old blob cannot be
132
+ // upgraded; surface that so callers can prompt re-auth with a
133
+ // clear signal instead of silently returning `empty`.
134
+ let current = parsed;
135
+ let currentVersion = storedVersion;
136
+ while (currentVersion !== expectedVersion) {
137
+ const migrator = migrators.get(currentVersion);
138
+ if (!migrator) {
139
+ return { ok: false, reason: "version-mismatch", storedVersion };
140
+ }
141
+ const next = migrator(current);
142
+ if (next === null) {
143
+ return { ok: false, reason: "version-mismatch", storedVersion };
144
+ }
145
+ const nextVersion = getStoredVersion(next);
146
+ if (nextVersion === null || nextVersion <= currentVersion) {
147
+ // Migrator output is malformed or didn't advance. Treat the
148
+ // stored blob as un-migratable rather than loop forever.
149
+ return { ok: false, reason: "version-mismatch", storedVersion };
150
+ }
151
+ current = next;
152
+ currentVersion = nextVersion;
153
+ }
154
+ return { ok: true, blob: current };
155
+ }
156
+ function wrapKeyringError(op, cause) {
157
+ const causeMessage = cause instanceof Error ? cause.message : String(cause);
158
+ throw new errors_1.OAuthFlowError("KEYRING_UNAVAILABLE", `System keychain ${op} failed: ${causeMessage}. ${platformKeyringHint()}`, { cause });
159
+ }
160
+ /**
161
+ * Returns a per-platform hint appended to keychain error messages so
162
+ * users see actionable guidance for their OS instead of generic or
163
+ * Linux-only advice. Exported (but not re-exported from the package
164
+ * index) so tests can exercise each branch without mocking
165
+ * `process.platform`.
166
+ */
167
+ function platformKeyringHint(platform = process.platform) {
168
+ switch (platform) {
169
+ case "darwin":
170
+ return "On macOS this usually means Keychain Access denied or cancelled the prompt.";
171
+ case "win32":
172
+ return "On Windows this usually means Credential Manager rejected the operation.";
173
+ case "linux":
174
+ return "On Linux this usually means no D-Bus Secret Service is running (e.g. GNOME Keyring or KWallet).";
175
+ default:
176
+ return `Underlying platform: ${platform}.`;
177
+ }
178
+ }
179
+ /**
180
+ * `TokenStore` backed by the operating system's native keychain via
181
+ * `@napi-rs/keyring` (macOS Keychain, Windows Credential Manager, Linux
182
+ * Secret Service). One entry per machine, keyed by a fixed account
183
+ * name; the blob carries its own issuer/client coordinates so verbs
184
+ * can recover full config without per-issuer keying.
185
+ */
186
+ class KeyringTokenStore {
187
+ #entry;
188
+ constructor(entryFactory = keyringBinding_1.defaultEntryFactory) {
189
+ this.#entry = entryFactory(SERVICE_NAME, ACCOUNT_NAME);
190
+ }
191
+ async save(entry) {
192
+ try {
193
+ this.#entry.setPassword(JSON.stringify(entryToBlob(entry)));
194
+ }
195
+ catch (cause) {
196
+ wrapKeyringError("write", cause);
197
+ }
198
+ }
199
+ async load() {
200
+ let raw;
201
+ try {
202
+ raw = this.#entry.getPassword();
203
+ }
204
+ catch (cause) {
205
+ wrapKeyringError("read", cause);
206
+ }
207
+ const chain = parseAndMigrateBlob(raw);
208
+ if (!chain.ok)
209
+ return chain;
210
+ if (!isLatestBlob(chain.blob))
211
+ return { ok: false, reason: "corrupt" };
212
+ return { ok: true, entry: blobToEntry(chain.blob) };
213
+ }
214
+ async clear() {
215
+ try {
216
+ this.#entry.deletePassword();
217
+ }
218
+ catch (cause) {
219
+ wrapKeyringError("delete", cause);
220
+ }
221
+ }
222
+ }
223
+ exports.KeyringTokenStore = KeyringTokenStore;
@@ -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}`;