@deque/axe-auth 1.1.0-next.97bcb8e6 → 1.1.0-next.9c8d8c98

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 (76) hide show
  1. package/README.md +64 -7
  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 +119 -27
  28. package/dist/oauth/authorizationURL.d.ts +24 -0
  29. package/dist/oauth/authorizationURL.js +48 -0
  30. package/dist/oauth/authorize.d.ts +53 -0
  31. package/dist/oauth/authorize.js +117 -0
  32. package/dist/oauth/callbackServer.d.ts +23 -0
  33. package/dist/oauth/callbackServer.js +234 -0
  34. package/dist/oauth/discoverOIDC.d.ts +33 -0
  35. package/dist/oauth/discoverOIDC.js +144 -0
  36. package/dist/oauth/discoverSSOConfig.d.ts +37 -0
  37. package/dist/oauth/discoverSSOConfig.js +105 -0
  38. package/dist/oauth/errors.d.ts +77 -0
  39. package/dist/oauth/errors.js +48 -0
  40. package/dist/oauth/getValidAccessToken.d.ts +54 -0
  41. package/dist/oauth/getValidAccessToken.js +131 -0
  42. package/dist/oauth/index.d.ts +16 -0
  43. package/dist/oauth/index.js +19 -0
  44. package/dist/oauth/issuerURL.d.ts +22 -0
  45. package/dist/oauth/issuerURL.js +38 -0
  46. package/dist/oauth/keyringBinding.d.ts +22 -0
  47. package/dist/oauth/keyringBinding.js +41 -0
  48. package/dist/oauth/logo.generated.d.ts +1 -0
  49. package/dist/oauth/logo.generated.js +7 -0
  50. package/dist/oauth/openBrowser.d.ts +30 -0
  51. package/dist/oauth/openBrowser.js +95 -0
  52. package/dist/oauth/pkce.d.ts +17 -0
  53. package/dist/oauth/pkce.js +43 -0
  54. package/dist/oauth/predicates.d.ts +7 -0
  55. package/dist/oauth/predicates.js +15 -0
  56. package/dist/oauth/refreshTokens.d.ts +30 -0
  57. package/dist/oauth/refreshTokens.js +60 -0
  58. package/dist/oauth/renderHtml.d.ts +9 -0
  59. package/dist/oauth/renderHtml.js +60 -0
  60. package/dist/oauth/revokeToken.d.ts +28 -0
  61. package/dist/oauth/revokeToken.js +63 -0
  62. package/dist/oauth/testUtils.d.ts +35 -0
  63. package/dist/oauth/testUtils.js +61 -0
  64. package/dist/oauth/tokenExchange.d.ts +26 -0
  65. package/dist/oauth/tokenExchange.js +44 -0
  66. package/dist/oauth/tokenResponse.d.ts +22 -0
  67. package/dist/oauth/tokenResponse.js +101 -0
  68. package/dist/oauth/tokenStore.d.ts +171 -0
  69. package/dist/oauth/tokenStore.js +545 -0
  70. package/dist/userAgent.d.ts +12 -0
  71. package/dist/userAgent.js +18 -0
  72. package/docs/architecture.md +201 -0
  73. package/docs/callback-page.md +24 -0
  74. package/docs/callback-server.md +21 -0
  75. package/docs/oauth-flow.md +15 -0
  76. package/package.json +21 -4
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ // Generated by scripts/encode-logo.js — do not edit by hand.
3
+ // Source: assets/logo.png
4
+ // To regenerate: node scripts/encode-logo.js
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LOGO_PNG_BASE64 = void 0;
7
+ exports.LOGO_PNG_BASE64 = "iVBORw0KGgoAAAANSUhEUgAAALQAAAC0CAYAAAA9zQYyAAAgAElEQVR4nO2df4wd13XfP2dBEIRAEKpKEIKqCISgEo7gOKqqKPsYpXEE1b8i/4rtWo6jJP7RuLHqtq7gt0kdwXANp9jn2Ibr2IkTJc4PO45l2bUMNZV/xHZcRW+jyI4iCKoqCASjCgShCiyhEARBEHv6x7x755wz9y13982bt+R7X2D3zdy5c+fMne+ce865P0ZY4OJHf7gXkX9AFSQlCqDVr2qdV0YZVKttZZSPkEdBZVReOi7mPE1Jn2O1d/s0bquEpa4utMAsYQim6U8DT6VxSk1KqX/Te5A2dERs94Kkc6TxLkwbC0LPCxLB8naCmvSUlLRvIqnR7ApIeiswJFdcpqTZw3sybezq9nILzA7ZBKgh4VjWrliTwaeJ+HOcGWNNl/Yk3woWhJ4bWGbatFKSeJKKIbolf8xDIU/HNsfC5JgLaNMk2CBrZXJoyFpIU6vZNaSlcyaTfKtYEHouYO3htA9FthlTu9oPtoMleHQcG5ER6dz0WBB6LhCiFWPzRBtYg8YlEF58mRJNmI7VMwsbek4gxuRITpyNPwcil3iYNLDajNTlNdK7t59hQej5gViibZDm0kdIpkTudMH4mOklscdmR+oFoecG6oMcasjmzOtkC9enNezv7OyFnkEJhXWvoBc29FzBak5J+8budd3iZlsDma1TmX/dG1D/LTpWFpgOpNaqjbhxodvbEl0DwZ0mDmZIo5xusdDQc4XUjZ1IaGLHGvbtr1W+NkZNLAdfdoyQdIAFoecJ0bGzv04rh18bvsuDjoydncZzFB3DbrEg9LygGE8ORCwFJdxoOnu++LxWw1uid4wFoecFpVBcA4WBRpn0+BCz/cUcj13fHWNB6LlDIJnrXCmN9Wio7HIeZ5KEXscOsSD0vMHGm+2vD0bj1W+JoCGcJ1GFF8yUDrAg9DzBDR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QnkKYMzoQIeRuyB7naxTqq9wCvZLB8dCpX6BgXPqETBr1ngZcDA9CzzUHrBK1aH8p2LLDjP17fHtaBDyHyFga9k62XPiNMs0GbDfprS6CvAPkkwtVFzWYdtwaMuWDDZzm8MabK8osRzJK4GmmMkmhISwk5LcnTctf3RYqLR0MnDJbXEf4c9KdQ/cNKW4+OJds0Q2lo7kh2d24hLf8aImbtnWxvbV638TaF6+fzgjwLbIiLj9AAq73KBBH+NfCmaiEUqENko+04dsJip328/uJrS6eCi5PQCau9cwx6XwP5CeADKM83TYcY7Qi/LsqhNElnnTqTd1xZOfYdVK51AJOpYp3ShYbeFC5uQicMlk+i/GegB9xN4xspGIKZ3xwBsXAGrydaqWcvd5aEUF5uHQphkvTONMKEC5wP81lN/eG1wJ2I3AZc0nDMNrJbx+WLDp6t2XH7G/mbUdG3PcD/IsV8aOiIQe8JkHeg+iOofgw4Doxx3gihNYzpgTmuBWJqHbrL2jhtU3Y0nSMZyl7gvJhPQkM1EXfQOwJyJ+iPoPou4EEYzYTOXdej/NEEGBdQdhaJtc+NObJhD2CD4YVrLTAOi5qyWBnuRrkWeAPwGpBDCNWM72geRLiZJUlbm8xuTLUhdDY/gr2SN3P6Ig69CSwIXUL10Z89wLXALcDLEV4Msh9lKZM31t6mbOcxzmaeadNIPwscAx4C3s+gd3Sym7u4sSD0ZlAR/ADVdwlvBHqg1wJXgOymMTfTaujRPjBWvVfZ1oFzKKeAowiPojIEfQR4eqesv7zTsSD0dlF9T3w/yNWgB4GDID8EejnIftB9IHsRHU3qFagGA50GTiFyAngeOAb69yhHqT5a+QzwwmgiwwJbxP8Hm/uj5T1hsjYAAAAASUVORK5CYII=";
@@ -0,0 +1,30 @@
1
+ import type { ChildProcess, SpawnOptions } from "node:child_process";
2
+ /** Injection seam for `child_process.spawn`. Used by tests. */
3
+ export type SpawnFn = (command: string, args: readonly string[], options: SpawnOptions) => ChildProcess;
4
+ /** Options for `openBrowser`. */
5
+ export interface OpenBrowserOptions {
6
+ /** Override for `process.platform`. Used by tests. */
7
+ platform?: NodeJS.Platform;
8
+ /** Override for `child_process.spawn`. Used by tests. */
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;
19
+ }
20
+ /**
21
+ * Launches the system browser at `url` in a detached child process.
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.
26
+ *
27
+ * @param url Absolute URL to open.
28
+ * @param options Platform/spawn/env overrides; only exposed for tests.
29
+ */
30
+ export declare function openBrowser(url: string, options?: OpenBrowserOptions): void;
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openBrowser = openBrowser;
4
+ const node_child_process_1 = require("node:child_process");
5
+ const shlex_1 = require("shlex");
6
+ const errors_1 = require("./errors");
7
+ // On Windows `start` is a cmd.exe builtin, not a standalone binary.
8
+ // The empty `""` pair is a positional placeholder for the window
9
+ // title — without it `start` treats the URL as the title.
10
+ //
11
+ // The escape class covers:
12
+ // - `& | ^ < >` — cmd metacharacters that would otherwise split the
13
+ // command line.
14
+ // - `"` — would prematurely terminate the argument and break
15
+ // `start`'s quoting.
16
+ // - `%` — triggers cmd.exe environment-variable expansion (e.g.
17
+ // `%USERNAME%`), which could leak or alter the URL.
18
+ // - `\r \n` — embedded newlines let a crafted URL inject additional
19
+ // commands onto cmd.exe's line.
20
+ //
21
+ // URLs normally percent-encode most of these (so this is defense in
22
+ // depth), but we do not fully trust the authorization endpoint that
23
+ // came back from discovery.
24
+ function windowsCommand(url) {
25
+ return {
26
+ command: "cmd.exe",
27
+ args: ["/c", "start", '""', url.replace(/[&|^<>"%\r\n]/g, (c) => `^${c}`)],
28
+ };
29
+ }
30
+ function browserCommand(platform, url, browserOverride) {
31
+ if (browserOverride && browserOverride.length > 0) {
32
+ const [command, ...extraArgs] = browserOverride;
33
+ return { command, args: [...extraArgs, url] };
34
+ }
35
+ switch (platform) {
36
+ case "darwin":
37
+ return { command: "open", args: [url] };
38
+ case "win32":
39
+ return windowsCommand(url);
40
+ default:
41
+ // linux / freebsd / openbsd — xdg-open is part of xdg-utils which
42
+ // is near-universal on desktop Linux. Environments without it
43
+ // (headless servers, containers) will report the missing binary
44
+ // via an asynchronous child-process `error` event, which this
45
+ // module deliberately swallows (see `child.once("error", ...)`
46
+ // below); `BROWSER_LAUNCH_FAILED` is only raised for synchronous
47
+ // `spawn()` throws. The caller's fallback is the URL already
48
+ // surfaced via `onAuthorizationUrl` so the user can finish the
49
+ // flow manually.
50
+ return { command: "xdg-open", args: [url] };
51
+ }
52
+ }
53
+ /**
54
+ * Launches the system browser at `url` in a detached child process.
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.
59
+ *
60
+ * @param url Absolute URL to open.
61
+ * @param options Platform/spawn/env overrides; only exposed for tests.
62
+ */
63
+ function openBrowser(url, options = {}) {
64
+ const platform = options.platform ?? process.platform;
65
+ const spawnFn = options.spawnFn ?? node_child_process_1.spawn;
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);
77
+ let child;
78
+ try {
79
+ child = spawnFn(command, args, {
80
+ detached: true,
81
+ stdio: "ignore",
82
+ });
83
+ }
84
+ catch (cause) {
85
+ throw new errors_1.OAuthFlowError("BROWSER_LAUNCH_FAILED", `Failed to launch the system browser (${command}). Open this URL manually:\n${url}`, { cause });
86
+ }
87
+ // `spawn` itself can succeed (the parent fork was fine) and then emit
88
+ // `error` asynchronously if the binary isn't on PATH. We can't surface
89
+ // that synchronously, but attaching a handler prevents the default
90
+ // "unhandled error" crash. Callers get a benign no-op if the browser
91
+ // never opens; the authorize() orchestrator prints the URL alongside
92
+ // the launch so the user has a fallback.
93
+ child.once("error", () => { });
94
+ child.unref();
95
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Generates a cryptographically random PKCE `code_verifier` per RFC 7636
3
+ * §4.1. 43 base64url characters, 256 bits of entropy.
4
+ */
5
+ export declare function generateCodeVerifier(): string;
6
+ /**
7
+ * Derives the PKCE S256 `code_challenge` for the given verifier per
8
+ * RFC 7636 §4.2: `BASE64URL(SHA256(ASCII(verifier)))`.
9
+ *
10
+ * @param verifier The PKCE verifier produced by `generateCodeVerifier`.
11
+ */
12
+ export declare function deriveCodeChallenge(verifier: string): string;
13
+ /**
14
+ * Generates a cryptographically random OAuth `state` value for CSRF
15
+ * protection. 22 base64url characters, 128 bits of entropy.
16
+ */
17
+ export declare function generateState(): string;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateCodeVerifier = generateCodeVerifier;
4
+ exports.deriveCodeChallenge = deriveCodeChallenge;
5
+ exports.generateState = generateState;
6
+ const node_crypto_1 = require("node:crypto");
7
+ // PKCE per RFC 7636. We only ever emit S256; plain is permitted by the RFC
8
+ // but explicitly disallowed by our authorization-server config so it can't
9
+ // silently fall back in the face of a buggy server.
10
+ /**
11
+ * Entropy for the PKCE `code_verifier`. 32 bytes yields 43 base64url chars
12
+ * (no padding), the minimum length RFC 7636 allows (43–128). 256 bits
13
+ * matches the S256 hash's security ceiling.
14
+ */
15
+ const VERIFIER_ENTROPY_BYTES = 32;
16
+ /**
17
+ * Entropy for the CSRF `state` parameter. 16 bytes yields 22 base64url
18
+ * chars — unguessable without bloating the authorization URL.
19
+ */
20
+ const STATE_ENTROPY_BYTES = 16;
21
+ /**
22
+ * Generates a cryptographically random PKCE `code_verifier` per RFC 7636
23
+ * §4.1. 43 base64url characters, 256 bits of entropy.
24
+ */
25
+ function generateCodeVerifier() {
26
+ return (0, node_crypto_1.randomBytes)(VERIFIER_ENTROPY_BYTES).toString("base64url");
27
+ }
28
+ /**
29
+ * Derives the PKCE S256 `code_challenge` for the given verifier per
30
+ * RFC 7636 §4.2: `BASE64URL(SHA256(ASCII(verifier)))`.
31
+ *
32
+ * @param verifier The PKCE verifier produced by `generateCodeVerifier`.
33
+ */
34
+ function deriveCodeChallenge(verifier) {
35
+ return (0, node_crypto_1.createHash)("sha256").update(verifier, "ascii").digest("base64url");
36
+ }
37
+ /**
38
+ * Generates a cryptographically random OAuth `state` value for CSRF
39
+ * protection. 22 base64url characters, 128 bits of entropy.
40
+ */
41
+ function generateState() {
42
+ return (0, node_crypto_1.randomBytes)(STATE_ENTROPY_BYTES).toString("base64url");
43
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Narrows `v` to `string` when it is a non-empty string. Useful for
3
+ * validating JSON fields from authorization-server responses, where
4
+ * the spec declares a field as "string" but servers occasionally
5
+ * return `""` / `null` / missing.
6
+ */
7
+ export declare function isNonEmptyString(v: unknown): v is string;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ // Type-guard predicates shared across the oauth modules. Keep this
3
+ // narrow: anything more substantial than a one-liner probably
4
+ // belongs in its own module rather than piling in here.
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isNonEmptyString = isNonEmptyString;
7
+ /**
8
+ * Narrows `v` to `string` when it is a non-empty string. Useful for
9
+ * validating JSON fields from authorization-server responses, where
10
+ * the spec declares a field as "string" but servers occasionally
11
+ * return `""` / `null` / missing.
12
+ */
13
+ function isNonEmptyString(v) {
14
+ return typeof v === "string" && v.length > 0;
15
+ }
@@ -0,0 +1,30 @@
1
+ import { type TokenSet } from "./tokenResponse";
2
+ /** Options for `refreshTokens`. */
3
+ export interface RefreshTokensOptions {
4
+ /** Token endpoint resolved from OIDC discovery. */
5
+ tokenEndpoint: string;
6
+ /** OAuth client identifier. */
7
+ clientId: string;
8
+ /** The refresh token to exchange for a new access token. */
9
+ refreshToken: string;
10
+ /** Source of `now`. Defaults to `Date.now`. Injected for test determinism. */
11
+ now?: () => number;
12
+ /** Aborts the underlying fetch when fired. */
13
+ signal?: AbortSignal;
14
+ }
15
+ /**
16
+ * Exchanges a refresh token for a fresh access token via RFC 6749 §6.
17
+ *
18
+ * Some providers (Keycloak by default) rotate refresh tokens and
19
+ * return a new one in the response; others leave the refresh token
20
+ * alone. When the server omits `refresh_token` from the response,
21
+ * the returned `TokenSet` carries forward the input `refreshToken`
22
+ * so callers never lose refresh capability after one use.
23
+ *
24
+ * @throws {OAuthFlowError} with code `TOKEN_EXCHANGE_FAILED` on any
25
+ * failure. `details` surfaces the OAuth `error` /
26
+ * `error_description` when present; callers distinguishing
27
+ * "refresh revoked" from "network hiccup" should inspect
28
+ * `details.error === "invalid_grant"`.
29
+ */
30
+ export declare function refreshTokens(options: RefreshTokensOptions): Promise<TokenSet>;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.refreshTokens = refreshTokens;
4
+ const errors_1 = require("./errors");
5
+ const tokenResponse_1 = require("./tokenResponse");
6
+ const userAgent_1 = require("../userAgent");
7
+ /**
8
+ * Exchanges a refresh token for a fresh access token via RFC 6749 §6.
9
+ *
10
+ * Some providers (Keycloak by default) rotate refresh tokens and
11
+ * return a new one in the response; others leave the refresh token
12
+ * alone. When the server omits `refresh_token` from the response,
13
+ * the returned `TokenSet` carries forward the input `refreshToken`
14
+ * so callers never lose refresh capability after one use.
15
+ *
16
+ * @throws {OAuthFlowError} with code `TOKEN_EXCHANGE_FAILED` on any
17
+ * failure. `details` surfaces the OAuth `error` /
18
+ * `error_description` when present; callers distinguishing
19
+ * "refresh revoked" from "network hiccup" should inspect
20
+ * `details.error === "invalid_grant"`.
21
+ */
22
+ async function refreshTokens(options) {
23
+ const now = options.now ?? Date.now;
24
+ // RFC 6749 §6 permits a `scope` parameter to request a subset of
25
+ // the originally-granted scopes. We deliberately omit it: Keycloak
26
+ // (our primary target) preserves the scope set across refresh, so
27
+ // re-sending would be redundant. Callers targeting a provider that
28
+ // reduces scopes when `scope` is omitted (some Okta configurations
29
+ // are rumored to) will need a provider-specific code path.
30
+ const body = new URLSearchParams({
31
+ grant_type: "refresh_token",
32
+ client_id: options.clientId,
33
+ refresh_token: options.refreshToken,
34
+ });
35
+ const issuedAt = now();
36
+ let response;
37
+ try {
38
+ response = await fetch(options.tokenEndpoint, {
39
+ method: "POST",
40
+ headers: {
41
+ "Content-Type": "application/x-www-form-urlencoded",
42
+ Accept: "application/json",
43
+ "User-Agent": userAgent_1.USER_AGENT,
44
+ },
45
+ body,
46
+ signal: options.signal,
47
+ });
48
+ }
49
+ catch (cause) {
50
+ throw new errors_1.OAuthFlowError("TOKEN_EXCHANGE_FAILED", `Could not reach the token endpoint at ${options.tokenEndpoint}. Check your network connection.`, { cause });
51
+ }
52
+ if (!response.ok) {
53
+ await (0, tokenResponse_1.throwTokenEndpointError)(response, "Token refresh");
54
+ }
55
+ const fresh = await (0, tokenResponse_1.parseTokenResponse)(response, issuedAt, options.tokenEndpoint);
56
+ return {
57
+ ...fresh,
58
+ refreshToken: fresh.refreshToken ?? options.refreshToken,
59
+ };
60
+ }
@@ -0,0 +1,9 @@
1
+ export type HtmlInput = {
2
+ kind: "success";
3
+ } | {
4
+ kind: "error";
5
+ reason: string;
6
+ description?: string;
7
+ };
8
+ export declare const CSP_HEADER: string;
9
+ export declare const renderHtml: (input: HtmlInput) => string;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderHtml = exports.CSP_HEADER = void 0;
4
+ const node_crypto_1 = require("node:crypto");
5
+ const logo_generated_1 = require("./logo.generated");
6
+ const CSS = `:root{--off-black:#666;--off-white:#fdfdfe;--white:#fff;--pink:#d71ef7;--blue:#3c7aae;--space-small:12px;--space-medium:24px;--space-large:36px;--space-huge:48px;--border-radius:3px}
7
+ html{box-sizing:border-box}
8
+ *,*::before,*::after{box-sizing:inherit}
9
+ *:focus{outline:2px solid var(--pink);outline-offset:2px}
10
+ body{margin:0;padding:0;width:100%;height:100%;font-family:Roboto,Helvetica,Arial,sans-serif;font-style:normal;font-weight:400;color:var(--off-black);background-color:var(--off-white);font-size:15px}
11
+ h1{padding:0;margin:0;font-size:34px;font-weight:700}
12
+ main{margin:var(--space-huge) auto;padding-left:var(--space-medium);padding-right:var(--space-medium);max-width:400px;text-align:center}
13
+ .hero{margin-bottom:var(--space-medium)}
14
+ .hero img{width:180px;max-width:100%;margin-bottom:var(--space-medium)}
15
+ .reason{margin-top:var(--space-medium);font-weight:500}
16
+ .description{margin-top:var(--space-small);font-size:13px}
17
+ .close{margin-top:var(--space-large)}`;
18
+ // CSP uses a SHA-256 hash of the <style> block contents instead of
19
+ // 'unsafe-inline'. Any drift between this digest and the rendered <style> tag
20
+ // causes the browser to refuse the stylesheet — see docs/callback-page.md.
21
+ const STYLE_HASH = (0, node_crypto_1.createHash)("sha256").update(CSS, "utf8").digest("base64");
22
+ exports.CSP_HEADER = `default-src 'none'; img-src data:; style-src 'sha256-${STYLE_HASH}'; frame-ancestors 'none'`;
23
+ // OWASP-recommended 5-character set for HTML body/attribute contexts;
24
+ // & must come first to avoid double-escaping. Not safe for JS/CSS/URL contexts.
25
+ // https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html#output-encoding-for-html-contexts
26
+ const escape = (s) => s
27
+ .replace(/&/g, "&amp;")
28
+ .replace(/</g, "&lt;")
29
+ .replace(/>/g, "&gt;")
30
+ .replace(/"/g, "&quot;")
31
+ .replace(/'/g, "&#39;");
32
+ const page = (title, body) => `<!doctype html>
33
+ <html lang="en">
34
+ <head>
35
+ <meta charset="UTF-8">
36
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
37
+ <title>${escape(title)}</title>
38
+ <style>${CSS}</style>
39
+ </head>
40
+ <body>
41
+ <main>
42
+ <div class="hero"><img src="data:image/png;base64,${logo_generated_1.LOGO_PNG_BASE64}" alt="Deque"></div>
43
+ ${body}
44
+ </main>
45
+ </body>
46
+ </html>`;
47
+ const renderHtml = (input) => {
48
+ if (input.kind === "success") {
49
+ return page("Authenticated", `<h1>Authenticated</h1>
50
+ <p class="close">You can close this tab and return to your terminal.</p>`);
51
+ }
52
+ const descriptionBlock = input.description
53
+ ? `<p class="description">${escape(input.description)}</p>`
54
+ : "";
55
+ return page("Authentication failed", `<h1>Authentication failed</h1>
56
+ <p class="reason">${escape(input.reason)}</p>
57
+ ${descriptionBlock}
58
+ <p class="close">You can close this tab and return to your terminal.</p>`);
59
+ };
60
+ exports.renderHtml = renderHtml;
@@ -0,0 +1,28 @@
1
+ /** Options for `revokeRefreshToken`. */
2
+ export interface RevokeRefreshTokenOptions {
3
+ /** Revocation endpoint resolved from OIDC discovery. */
4
+ revocationEndpoint: string;
5
+ /** OAuth client ID. */
6
+ clientId: string;
7
+ /** The refresh token to revoke server-side. */
8
+ refreshToken: string;
9
+ /** Aborts the underlying fetch when fired. */
10
+ signal?: AbortSignal;
11
+ }
12
+ /**
13
+ * Revokes a refresh token via RFC 7009. Servers SHOULD return 200
14
+ * regardless of whether the token was valid (the spec doesn't want
15
+ * revocation to be a probing oracle for token existence). In
16
+ * practice this helper still surfaces network errors and any
17
+ * non-2xx response from the revocation endpoint, on the assumption
18
+ * that a 4xx is more likely a misconfiguration the user should hear
19
+ * about than a routine condition to swallow.
20
+ *
21
+ * Throws a plain `Error` rather than `OAuthFlowError`: revocation
22
+ * is best-effort cleanup invoked from `axe-auth logout`, and the
23
+ * caller already handles failure by warning + continuing with the
24
+ * local clear. Adding a dedicated `OAuthFlowError` code for this
25
+ * one shallow operation is more bloat than the discrimination is
26
+ * worth.
27
+ */
28
+ export declare function revokeRefreshToken(options: RevokeRefreshTokenOptions): Promise<void>;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.revokeRefreshToken = revokeRefreshToken;
4
+ const userAgent_1 = require("../userAgent");
5
+ /**
6
+ * Revokes a refresh token via RFC 7009. Servers SHOULD return 200
7
+ * regardless of whether the token was valid (the spec doesn't want
8
+ * revocation to be a probing oracle for token existence). In
9
+ * practice this helper still surfaces network errors and any
10
+ * non-2xx response from the revocation endpoint, on the assumption
11
+ * that a 4xx is more likely a misconfiguration the user should hear
12
+ * about than a routine condition to swallow.
13
+ *
14
+ * Throws a plain `Error` rather than `OAuthFlowError`: revocation
15
+ * is best-effort cleanup invoked from `axe-auth logout`, and the
16
+ * caller already handles failure by warning + continuing with the
17
+ * local clear. Adding a dedicated `OAuthFlowError` code for this
18
+ * one shallow operation is more bloat than the discrimination is
19
+ * worth.
20
+ */
21
+ async function revokeRefreshToken(options) {
22
+ const body = new URLSearchParams({
23
+ token: options.refreshToken,
24
+ token_type_hint: "refresh_token",
25
+ client_id: options.clientId,
26
+ });
27
+ let response;
28
+ try {
29
+ response = await fetch(options.revocationEndpoint, {
30
+ method: "POST",
31
+ headers: {
32
+ "Content-Type": "application/x-www-form-urlencoded",
33
+ "User-Agent": userAgent_1.USER_AGENT,
34
+ },
35
+ body,
36
+ signal: options.signal,
37
+ });
38
+ }
39
+ catch (cause) {
40
+ const reason = cause instanceof Error ? cause.message : String(cause);
41
+ throw new Error(`Could not reach the revocation endpoint at ${options.revocationEndpoint}: ${reason}`, { cause });
42
+ }
43
+ if (!response.ok) {
44
+ // Deliberately do NOT include the response body. The request
45
+ // body we POSTed contains the refresh token; some Keycloak
46
+ // custom error templates and many WAFs / reverse proxies echo
47
+ // request fields back into 4xx pages, which would land the
48
+ // refresh token on stderr (the caller's `describeError(err)`
49
+ // path is `axe-auth: server-side revocation failed (...)`). Status
50
+ // alone is enough for the user to act on; if more detail is
51
+ // needed they can hit the revocation endpoint directly.
52
+ //
53
+ // We also drain the body so the underlying connection isn't
54
+ // held open by the unread stream.
55
+ try {
56
+ await response.text();
57
+ }
58
+ catch {
59
+ // ignore — body is purely diagnostic
60
+ }
61
+ throw new Error(`Revocation endpoint at ${options.revocationEndpoint} returned HTTP ${response.status}`);
62
+ }
63
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * A fixed "now" timestamp used by token-endpoint tests that need
3
+ * determinism for `expiresAt` assertions. Any constant would do;
4
+ * choosing one value keeps the arithmetic trivial to eyeball
5
+ * (2023-11-14T22:13:20.000Z).
6
+ */
7
+ export declare const FIXED_NOW = 1700000000000;
8
+ /** Signature matching the global `fetch` implementation. */
9
+ export type FetchMock = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
10
+ /**
11
+ * Swaps `globalThis.fetch` for `mock` while `fn` runs, then restores.
12
+ * Use in tests that mock *every* fetch the subject under test makes.
13
+ * (Tests that want pass-through-on-miss behavior should keep their
14
+ * own router — see `authorize.test.ts`.)
15
+ */
16
+ export declare function withFetch(mock: FetchMock, fn: () => Promise<void>): Promise<void>;
17
+ /**
18
+ * JSON-serialized `Response` with `Content-Type: application/json`
19
+ * already set. Any headers in `init.headers` merge on top.
20
+ */
21
+ export declare function jsonResponse(body: unknown, init?: ResponseInit): Response;
22
+ /**
23
+ * Canonical local Keycloak issuer URL used across tests — matches
24
+ * walnut's dev setup (`http://localhost:8080/auth/realms/local`).
25
+ * Use this anywhere a test needs "the Keycloak issuer" rather than
26
+ * a test-specific URL (e.g. `http://auth.test.invalid`).
27
+ */
28
+ export declare const KEYCLOAK_ISSUER = "http://localhost:8080/auth/realms/local";
29
+ /**
30
+ * Standard OAuth 2.0 token-endpoint success body. Returns a fresh
31
+ * plain object on each call so tests can safely mutate it after.
32
+ * Override any field via `overrides`; the happy-path defaults
33
+ * (Bearer, positive `expires_in`) are what most tests want.
34
+ */
35
+ export declare function tokenResponseBody(overrides?: Record<string, unknown>): Record<string, unknown>;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ // Shared helpers for the oauth test files. Not a `.test.ts` itself so
3
+ // the test runner doesn't pick it up directly, and excluded from c8
4
+ // coverage in `.c8rc.json` since nothing in here is production code.
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.KEYCLOAK_ISSUER = exports.FIXED_NOW = void 0;
7
+ exports.withFetch = withFetch;
8
+ exports.jsonResponse = jsonResponse;
9
+ exports.tokenResponseBody = tokenResponseBody;
10
+ /**
11
+ * A fixed "now" timestamp used by token-endpoint tests that need
12
+ * determinism for `expiresAt` assertions. Any constant would do;
13
+ * choosing one value keeps the arithmetic trivial to eyeball
14
+ * (2023-11-14T22:13:20.000Z).
15
+ */
16
+ exports.FIXED_NOW = 1_700_000_000_000;
17
+ /**
18
+ * Swaps `globalThis.fetch` for `mock` while `fn` runs, then restores.
19
+ * Use in tests that mock *every* fetch the subject under test makes.
20
+ * (Tests that want pass-through-on-miss behavior should keep their
21
+ * own router — see `authorize.test.ts`.)
22
+ */
23
+ function withFetch(mock, fn) {
24
+ const original = globalThis.fetch;
25
+ globalThis.fetch = mock;
26
+ return fn().finally(() => {
27
+ globalThis.fetch = original;
28
+ });
29
+ }
30
+ /**
31
+ * JSON-serialized `Response` with `Content-Type: application/json`
32
+ * already set. Any headers in `init.headers` merge on top.
33
+ */
34
+ function jsonResponse(body, init = { status: 200 }) {
35
+ return new Response(JSON.stringify(body), {
36
+ ...init,
37
+ headers: { "Content-Type": "application/json", ...(init.headers ?? {}) },
38
+ });
39
+ }
40
+ /**
41
+ * Canonical local Keycloak issuer URL used across tests — matches
42
+ * walnut's dev setup (`http://localhost:8080/auth/realms/local`).
43
+ * Use this anywhere a test needs "the Keycloak issuer" rather than
44
+ * a test-specific URL (e.g. `http://auth.test.invalid`).
45
+ */
46
+ exports.KEYCLOAK_ISSUER = "http://localhost:8080/auth/realms/local";
47
+ /**
48
+ * Standard OAuth 2.0 token-endpoint success body. Returns a fresh
49
+ * plain object on each call so tests can safely mutate it after.
50
+ * Override any field via `overrides`; the happy-path defaults
51
+ * (Bearer, positive `expires_in`) are what most tests want.
52
+ */
53
+ function tokenResponseBody(overrides = {}) {
54
+ return {
55
+ access_token: "at",
56
+ refresh_token: "rt",
57
+ expires_in: 300,
58
+ token_type: "Bearer",
59
+ ...overrides,
60
+ };
61
+ }
@@ -0,0 +1,26 @@
1
+ import { type TokenSet } from "./tokenResponse";
2
+ /** Options for `exchangeCodeForTokens`. */
3
+ export interface ExchangeCodeForTokensOptions {
4
+ /** Token endpoint resolved from OIDC discovery. */
5
+ tokenEndpoint: string;
6
+ /** OAuth client identifier. */
7
+ clientId: string;
8
+ /** Authorization code received via the loopback callback. */
9
+ code: string;
10
+ /** PKCE verifier paired with the `code_challenge` sent at auth time. */
11
+ codeVerifier: string;
12
+ /** Redirect URI originally sent to the authorization endpoint. */
13
+ redirectUri: string;
14
+ /** Source of `now`. Injected for test determinism; defaults to `Date.now`. */
15
+ now?: () => number;
16
+ /** Aborts the underlying fetch when fired. */
17
+ signal?: AbortSignal;
18
+ }
19
+ /**
20
+ * Exchanges an authorization code for a `TokenSet` via the
21
+ * authorization server's token endpoint (RFC 6749 §4.1.3 + RFC 7636
22
+ * §4.5). Rejects with `OAuthFlowError("TOKEN_EXCHANGE_FAILED", ...)`
23
+ * for any failure mode, surfacing the OAuth `error` /
24
+ * `error_description` when available.
25
+ */
26
+ export declare function exchangeCodeForTokens(options: ExchangeCodeForTokensOptions): Promise<TokenSet>;