@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.
- package/README.md +20 -26
- package/credits.json +53 -0
- package/dist/cli/commonArgs.d.ts +53 -37
- package/dist/cli/commonArgs.help.d.ts +1 -1
- package/dist/cli/commonArgs.help.js +12 -11
- package/dist/cli/commonArgs.js +37 -66
- package/dist/cli/errors.d.ts +0 -10
- package/dist/cli/errors.js +1 -16
- package/dist/cli/testUtils.js +3 -3
- package/dist/cli/types.d.ts +8 -11
- package/dist/commands/login.d.ts +3 -0
- package/dist/commands/login.help.d.ts +1 -1
- package/dist/commands/login.help.js +11 -5
- package/dist/commands/login.js +38 -14
- package/dist/commands/logout.d.ts +1 -1
- package/dist/commands/logout.help.d.ts +1 -1
- package/dist/commands/logout.help.js +5 -4
- package/dist/commands/logout.js +1 -15
- package/dist/commands/token.d.ts +2 -7
- package/dist/commands/token.help.d.ts +1 -1
- package/dist/commands/token.help.js +5 -5
- package/dist/commands/token.js +10 -22
- package/dist/index.js +23 -51
- package/dist/oauth/authorize.d.ts +7 -0
- package/dist/oauth/authorize.js +2 -1
- package/dist/oauth/discoverOIDC.js +31 -1
- package/dist/oauth/discoverSSOConfig.d.ts +47 -0
- package/dist/oauth/discoverSSOConfig.js +105 -0
- package/dist/oauth/errors.d.ts +2 -0
- package/dist/oauth/getValidAccessToken.js +1 -0
- package/dist/oauth/openBrowser.d.ts +14 -3
- package/dist/oauth/openBrowser.js +22 -5
- package/dist/oauth/refreshTokens.js +2 -0
- package/dist/oauth/revokeToken.js +5 -1
- package/dist/oauth/tokenExchange.js +2 -0
- package/dist/oauth/tokenStore.d.ts +52 -3
- package/dist/oauth/tokenStore.js +369 -18
- package/dist/userAgent.d.ts +12 -0
- package/dist/userAgent.js +18 -0
- package/docs/architecture.md +201 -0
- package/docs/callback-page.md +24 -0
- package/docs/callback-server.md +21 -0
- package/docs/oauth-flow.md +15 -0
- 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
|
-
*
|
|
14
|
-
*
|
|
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
|
-
*
|
|
51
|
-
*
|
|
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
|
|
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: {
|
|
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,53 @@ 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
|
+
* Returns a per-platform hint appended to keychain error messages so
|
|
113
|
+
* users see actionable guidance for their OS instead of generic or
|
|
114
|
+
* Linux-only advice. Exported (but not re-exported from the package
|
|
115
|
+
* index) so tests can exercise each branch without mocking
|
|
116
|
+
* `process.platform`.
|
|
117
|
+
*/
|
|
118
|
+
export declare function platformKeyringHint(platform?: NodeJS.Platform): string;
|
|
98
119
|
/**
|
|
99
120
|
* `TokenStore` backed by the operating system's native keychain via
|
|
100
121
|
* `@napi-rs/keyring` (macOS Keychain, Windows Credential Manager, Linux
|
|
101
|
-
* Secret Service).
|
|
102
|
-
*
|
|
103
|
-
*
|
|
122
|
+
* Secret Service). On macOS and Linux the blob lives in a single entry
|
|
123
|
+
* keyed by the fixed `credentials` account name. On Windows the blob
|
|
124
|
+
* is split across `credentials.0`, `credentials.1`, … entries to fit
|
|
125
|
+
* under Credential Manager's 2560 UTF-16 character per-entry cap; see
|
|
126
|
+
* `shouldChunkForKeyring`.
|
|
127
|
+
*
|
|
128
|
+
* The blob carries its own issuer/client coordinates so verbs can
|
|
129
|
+
* recover full config without per-issuer keying.
|
|
104
130
|
*/
|
|
105
131
|
export declare class KeyringTokenStore implements TokenStore {
|
|
106
132
|
#private;
|
|
133
|
+
/**
|
|
134
|
+
* @param entryFactory Injection seam for `@napi-rs/keyring` entries.
|
|
135
|
+
* Defaults to the production lazy-resolved factory; tests pass a
|
|
136
|
+
* recording / faking variant.
|
|
137
|
+
*/
|
|
107
138
|
constructor(entryFactory?: KeyringEntryFactory);
|
|
139
|
+
/**
|
|
140
|
+
* @internal Test seam. Constructs a store with an explicit chunking
|
|
141
|
+
* decision instead of the platform-determined default, so the
|
|
142
|
+
* chunked path can be exercised on macOS/Linux CI and the unchunked
|
|
143
|
+
* path on Windows CI. Production code must use the regular
|
|
144
|
+
* constructor and let `shouldChunkForKeyring()` decide — passing
|
|
145
|
+
* `chunked: true` on macOS would write data that the regular
|
|
146
|
+
* constructor wouldn't be able to read.
|
|
147
|
+
*/
|
|
148
|
+
static forTesting(entryFactory: KeyringEntryFactory, chunked: boolean): KeyringTokenStore;
|
|
108
149
|
save(entry: StoredEntry): Promise<void>;
|
|
109
150
|
load(): Promise<LoadResult>;
|
|
110
151
|
clear(): Promise<void>;
|
|
111
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Splits `blob` into the N parts that `KeyringTokenStore.#saveChunked`
|
|
155
|
+
* writes to `credentials.0..N-1`. Chunk 0 is prefixed with `<N>\n` so
|
|
156
|
+
* the reader can learn N from a single getPassword call. Each chunk
|
|
157
|
+
* stays under `CHUNK_LIMIT` UTF-16 characters; throws if the blob would
|
|
158
|
+
* require more than `MAX_CHUNKS` chunks. Exported for tests.
|
|
159
|
+
*/
|
|
160
|
+
export declare function chunkBlobForKeyring(blob: string): string[];
|