@deque/axe-auth 1.1.0-next.fda76051 → 1.1.0-rc.047d31b4
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 +58 -17
- package/credits.json +53 -0
- package/dist/cli/commonArgs.d.ts +35 -0
- package/dist/cli/commonArgs.help.d.ts +2 -0
- package/dist/cli/commonArgs.help.js +20 -0
- package/dist/cli/commonArgs.js +63 -0
- package/dist/cli/confirm.d.ts +17 -0
- package/dist/cli/confirm.js +53 -0
- package/dist/cli/errors.d.ts +13 -0
- package/dist/cli/errors.js +30 -0
- package/dist/cli/testUtils.d.ts +52 -0
- package/dist/cli/testUtils.js +100 -0
- package/dist/cli/types.d.ts +39 -0
- package/dist/cli/types.js +2 -0
- package/dist/commands/login.d.ts +41 -0
- package/dist/commands/login.help.d.ts +2 -0
- package/dist/commands/login.help.js +41 -0
- package/dist/commands/login.js +108 -0
- package/dist/commands/logout.d.ts +24 -0
- package/dist/commands/logout.help.d.ts +2 -0
- package/dist/commands/logout.help.js +38 -0
- package/dist/commands/logout.js +68 -0
- package/dist/commands/token.d.ts +21 -0
- package/dist/commands/token.help.d.ts +2 -0
- package/dist/commands/token.help.js +41 -0
- package/dist/commands/token.js +40 -0
- package/dist/index.js +107 -22
- package/dist/oauth/authorizationURL.d.ts +1 -6
- package/dist/oauth/authorizationURL.js +2 -6
- package/dist/oauth/authorize.d.ts +13 -44
- package/dist/oauth/authorize.js +4 -5
- package/dist/oauth/discoverOIDC.d.ts +10 -27
- package/dist/oauth/discoverOIDC.js +33 -32
- package/dist/oauth/discoverSSOConfig.d.ts +37 -0
- package/dist/oauth/discoverSSOConfig.js +105 -0
- package/dist/oauth/errors.d.ts +2 -0
- package/dist/oauth/getValidAccessToken.d.ts +9 -44
- package/dist/oauth/getValidAccessToken.js +8 -16
- package/dist/oauth/openBrowser.d.ts +14 -3
- package/dist/oauth/openBrowser.js +22 -5
- package/dist/oauth/refreshTokens.js +2 -3
- package/dist/oauth/revokeToken.js +5 -1
- package/dist/oauth/tokenExchange.js +2 -0
- package/dist/oauth/tokenResponse.d.ts +6 -38
- package/dist/oauth/tokenResponse.js +7 -27
- package/dist/oauth/tokenStore.d.ts +63 -3
- package/dist/oauth/tokenStore.js +379 -32
- 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 +21 -5
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HELP_LOGIN = void 0;
|
|
4
|
+
const commonArgs_help_1 = require("../cli/commonArgs.help");
|
|
5
|
+
/** Help text for `axe-auth login --help`. */
|
|
6
|
+
exports.HELP_LOGIN = `axe-auth login
|
|
7
|
+
|
|
8
|
+
Open a browser, complete the OAuth 2.0 Authorization Code + PKCE
|
|
9
|
+
flow against the customer's Keycloak realm, and persist the
|
|
10
|
+
resulting tokens to the OS keychain.
|
|
11
|
+
|
|
12
|
+
The CLI discovers the OAuth coordinates by calling
|
|
13
|
+
\`<server>/api/sso-config\` on the axe server, so users only need to
|
|
14
|
+
supply (or default to) the axe server URL — never the underlying
|
|
15
|
+
Keycloak URL, realm, or client ID directly.
|
|
16
|
+
|
|
17
|
+
Usage:
|
|
18
|
+
axe-auth login [--server <url>] [--force]
|
|
19
|
+
|
|
20
|
+
With no flags, the SaaS prod axe server URL (https://axe.deque.com)
|
|
21
|
+
is used. Customers on other deployments pass --server (or set
|
|
22
|
+
AXE_SERVER_URL).
|
|
23
|
+
|
|
24
|
+
Options:
|
|
25
|
+
${commonArgs_help_1.HELP_COMMON_OPTIONS}
|
|
26
|
+
--force Re-authenticate without prompting even if
|
|
27
|
+
a valid token is already stored.
|
|
28
|
+
|
|
29
|
+
Behavior when already authenticated:
|
|
30
|
+
axe-auth stores one entry per machine. If a valid entry already
|
|
31
|
+
exists, an interactive session prompts for confirmation before
|
|
32
|
+
overwriting it — even when the new login targets a different
|
|
33
|
+
issuer or client (logging in to B destroys A's tokens). Pass
|
|
34
|
+
--force to skip the prompt. In a non-interactive session (no TTY)
|
|
35
|
+
--force is required; otherwise the command refuses to overwrite
|
|
36
|
+
stored tokens and exits non-zero.
|
|
37
|
+
|
|
38
|
+
Exit codes:
|
|
39
|
+
0 Success; tokens persisted to the keychain.
|
|
40
|
+
2 Configuration error or flow failure.
|
|
41
|
+
3 Login cancelled at the prompt.`;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const ts_dedent_1 = require("ts-dedent");
|
|
7
|
+
const remove_trailing_slash_1 = __importDefault(require("remove-trailing-slash"));
|
|
8
|
+
const authorize_1 = require("../oauth/authorize");
|
|
9
|
+
const discoverSSOConfig_1 = require("../oauth/discoverSSOConfig");
|
|
10
|
+
const errors_1 = require("../oauth/errors");
|
|
11
|
+
const tokenStore_1 = require("../oauth/tokenStore");
|
|
12
|
+
const confirm_1 = require("../cli/confirm");
|
|
13
|
+
const login_help_1 = require("./login.help");
|
|
14
|
+
const errors_2 = require("../cli/errors");
|
|
15
|
+
/** `axe-auth login` — drive the OAuth flow and persist tokens. */
|
|
16
|
+
const loginCommand = {
|
|
17
|
+
name: "login",
|
|
18
|
+
summary: "Open a browser, complete the OAuth flow, and persist tokens to the OS keychain.",
|
|
19
|
+
helpText: login_help_1.HELP_LOGIN,
|
|
20
|
+
options: {
|
|
21
|
+
force: { type: "boolean" },
|
|
22
|
+
},
|
|
23
|
+
requiresConfig: true,
|
|
24
|
+
async run(args, deps) {
|
|
25
|
+
const isInteractive = deps.isInteractive ?? Boolean(deps.stdin.isTTY);
|
|
26
|
+
const authorizeFn = deps.authorize ?? authorize_1.authorize;
|
|
27
|
+
const discoverFn = deps.discoverSSOConfig ?? discoverSSOConfig_1.discoverSSOConfig;
|
|
28
|
+
const confirmFn = deps.confirm ??
|
|
29
|
+
((prompt) => (0, confirm_1.confirm)({
|
|
30
|
+
question: prompt,
|
|
31
|
+
input: deps.stdin,
|
|
32
|
+
output: deps.stderr,
|
|
33
|
+
}));
|
|
34
|
+
const tokenStore = deps.tokenStore ?? new tokenStore_1.KeyringTokenStore();
|
|
35
|
+
let ssoConfig;
|
|
36
|
+
try {
|
|
37
|
+
ssoConfig = await discoverFn(args.walnutURL, {
|
|
38
|
+
allowInsecure: args.allowInsecureIssuer,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
if (err instanceof errors_1.OAuthFlowError) {
|
|
43
|
+
throw new errors_2.CLIError("OAUTH_FAILED", err.message);
|
|
44
|
+
}
|
|
45
|
+
throw err;
|
|
46
|
+
}
|
|
47
|
+
const issuerURL = `${(0, remove_trailing_slash_1.default)(ssoConfig.url)}/auth/realms/${ssoConfig.realm}`;
|
|
48
|
+
const clientId = ssoConfig.mcpClientId;
|
|
49
|
+
if (!args.force) {
|
|
50
|
+
const stored = deps.loadedEntry ?? (await tokenStore.load());
|
|
51
|
+
if (!stored.ok && stored.reason !== "empty") {
|
|
52
|
+
// authorize() will overwrite either way, but the user
|
|
53
|
+
// deserves a breadcrumb for what disappeared.
|
|
54
|
+
deps.stderr.write(`axe-auth: replacing unreadable stored credentials (${stored.reason}).\n`);
|
|
55
|
+
}
|
|
56
|
+
if (stored.ok) {
|
|
57
|
+
const sameIssuer = stored.entry.issuerURL === issuerURL &&
|
|
58
|
+
stored.entry.clientId === clientId;
|
|
59
|
+
if (!isInteractive) {
|
|
60
|
+
throw new errors_2.CLIError("ALREADY_AUTHENTICATED", sameIssuer
|
|
61
|
+
? `Already authenticated against ${issuerURL}. Re-run with --force to override.`
|
|
62
|
+
: (0, ts_dedent_1.dedent) `
|
|
63
|
+
Currently authenticated against ${stored.entry.issuerURL}.
|
|
64
|
+
Logging in to ${issuerURL} would replace those tokens.
|
|
65
|
+
Re-run with --force to override.
|
|
66
|
+
`);
|
|
67
|
+
}
|
|
68
|
+
const prompt = sameIssuer
|
|
69
|
+
? `Already authenticated against ${issuerURL}. Re-authenticate? [y/N]`
|
|
70
|
+
: (0, ts_dedent_1.dedent) `
|
|
71
|
+
Currently authenticated against ${stored.entry.issuerURL} (client ${stored.entry.clientId}).
|
|
72
|
+
Logging in to ${issuerURL} (client ${clientId}) will replace those tokens.
|
|
73
|
+
Continue? [y/N]
|
|
74
|
+
`;
|
|
75
|
+
const ok = await confirmFn(prompt);
|
|
76
|
+
if (!ok) {
|
|
77
|
+
throw new errors_2.CLIError("USER_CANCELLED", "Login cancelled.");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
// `walnutURL` lands in the StoredEntry so future verbs
|
|
82
|
+
// (re-discovery, revoke) operate without user-supplied flags.
|
|
83
|
+
try {
|
|
84
|
+
await authorizeFn({
|
|
85
|
+
issuerURL,
|
|
86
|
+
clientId,
|
|
87
|
+
walnutURL: args.walnutURL,
|
|
88
|
+
scopes: ["offline_access"],
|
|
89
|
+
allowInsecureIssuer: args.allowInsecureIssuer,
|
|
90
|
+
tokenStore,
|
|
91
|
+
onAuthorizationUrl: (url) => {
|
|
92
|
+
deps.stderr.write(`Authorization URL: ${url}\n`);
|
|
93
|
+
},
|
|
94
|
+
onWarning: (msg) => {
|
|
95
|
+
deps.stderr.write(`axe-auth: ${msg}\n`);
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
if (err instanceof errors_1.OAuthFlowError || err instanceof errors_1.OAuthCallbackError) {
|
|
101
|
+
throw new errors_2.CLIError("OAUTH_FAILED", err.message);
|
|
102
|
+
}
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
deps.stdout.write("✓ Authenticated.\n");
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
exports.default = loginCommand;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { discoverOIDC } from "../oauth/discoverOIDC";
|
|
2
|
+
import { revokeRefreshToken } from "../oauth/revokeToken";
|
|
3
|
+
import { type TokenStore } from "../oauth/tokenStore";
|
|
4
|
+
import type { CommonArgs } from "../cli/commonArgs";
|
|
5
|
+
import type { CommandDeps } from "../cli/types";
|
|
6
|
+
/** Verb-specific deps for `axe-auth logout`. */
|
|
7
|
+
export interface LogoutDeps extends CommandDeps {
|
|
8
|
+
/** Override the token store. Defaults to `KeyringTokenStore()`. */
|
|
9
|
+
tokenStore?: TokenStore;
|
|
10
|
+
/** Override OIDC discovery (for tests). */
|
|
11
|
+
discoverOIDC?: typeof discoverOIDC;
|
|
12
|
+
/** Override the revocation POST (for tests). */
|
|
13
|
+
revokeRefreshToken?: typeof revokeRefreshToken;
|
|
14
|
+
}
|
|
15
|
+
/** `axe-auth logout` — best-effort revoke + always clear local. */
|
|
16
|
+
declare const logoutCommand: {
|
|
17
|
+
name: string;
|
|
18
|
+
summary: string;
|
|
19
|
+
helpText: string;
|
|
20
|
+
options: {};
|
|
21
|
+
requiresConfig: false;
|
|
22
|
+
run(_args: CommonArgs, deps: LogoutDeps): Promise<void>;
|
|
23
|
+
};
|
|
24
|
+
export default logoutCommand;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** Help text for `axe-auth logout --help`. */
|
|
2
|
+
export declare const HELP_LOGOUT = "axe-auth logout\n\nRevoke the stored refresh token server-side (best-effort) and clear\nthe local OS keychain entry.\n\nUsage:\n axe-auth logout\n\n Operates exclusively on the keychain entry written by\n `axe-auth login`. The --server / --allow-insecure-issuer /\n --no-allow-insecure-issuer flags are accepted for parity with\n other commands but ignored; revocation uses the issuer, client,\n and insecure-issuer policy persisted alongside the tokens at login.\n\nOptions:\n --server <url> axe server URL. Used by `login` to fetch\n /api/sso-config and derive the OAuth\n coordinates. Falls back to AXE_SERVER_URL,\n then to https://axe.deque.com (SaaS prod).\n --allow-insecure-issuer Permit non-loopback http URLs (default is\n https only; loopback http is always\n allowed). Applies to `login` only;\n `token` and `logout` use the policy\n persisted at login.\n --no-allow-insecure-issuer\n Force allowInsecureIssuer=false for the new\n `login` (and the entry it persists).\n Ignored by `token` and `logout`.\n Mutually exclusive with\n --allow-insecure-issuer.\n -h, --help Show this help.\n\nBehavior:\n - If no tokens are stored, prints a note and exits 0 (logout is\n idempotent).\n - If the stored blob is unreadable (corrupt or from an\n unsupported schema version), the local entry is cleared without\n attempting server-side revocation, and a warning is printed.\n - Otherwise: discovers the revocation endpoint at the stored\n issuer, POSTs the stored refresh token per RFC 7009, then\n clears the local keychain entry. Revocation failures or a\n missing revocation endpoint are warned about; the local clear\n still runs.\n\nExit codes:\n 0 Tokens cleared (server-side revocation may have failed; see\n stderr for warnings).\n 2 Local clear failure.";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HELP_LOGOUT = void 0;
|
|
4
|
+
const commonArgs_help_1 = require("../cli/commonArgs.help");
|
|
5
|
+
/** Help text for `axe-auth logout --help`. */
|
|
6
|
+
exports.HELP_LOGOUT = `axe-auth logout
|
|
7
|
+
|
|
8
|
+
Revoke the stored refresh token server-side (best-effort) and clear
|
|
9
|
+
the local OS keychain entry.
|
|
10
|
+
|
|
11
|
+
Usage:
|
|
12
|
+
axe-auth logout
|
|
13
|
+
|
|
14
|
+
Operates exclusively on the keychain entry written by
|
|
15
|
+
\`axe-auth login\`. The --server / --allow-insecure-issuer /
|
|
16
|
+
--no-allow-insecure-issuer flags are accepted for parity with
|
|
17
|
+
other commands but ignored; revocation uses the issuer, client,
|
|
18
|
+
and insecure-issuer policy persisted alongside the tokens at login.
|
|
19
|
+
|
|
20
|
+
Options:
|
|
21
|
+
${commonArgs_help_1.HELP_COMMON_OPTIONS}
|
|
22
|
+
|
|
23
|
+
Behavior:
|
|
24
|
+
- If no tokens are stored, prints a note and exits 0 (logout is
|
|
25
|
+
idempotent).
|
|
26
|
+
- If the stored blob is unreadable (corrupt or from an
|
|
27
|
+
unsupported schema version), the local entry is cleared without
|
|
28
|
+
attempting server-side revocation, and a warning is printed.
|
|
29
|
+
- Otherwise: discovers the revocation endpoint at the stored
|
|
30
|
+
issuer, POSTs the stored refresh token per RFC 7009, then
|
|
31
|
+
clears the local keychain entry. Revocation failures or a
|
|
32
|
+
missing revocation endpoint are warned about; the local clear
|
|
33
|
+
still runs.
|
|
34
|
+
|
|
35
|
+
Exit codes:
|
|
36
|
+
0 Tokens cleared (server-side revocation may have failed; see
|
|
37
|
+
stderr for warnings).
|
|
38
|
+
2 Local clear failure.`;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const discoverOIDC_1 = require("../oauth/discoverOIDC");
|
|
4
|
+
const revokeToken_1 = require("../oauth/revokeToken");
|
|
5
|
+
const tokenStore_1 = require("../oauth/tokenStore");
|
|
6
|
+
const logout_help_1 = require("./logout.help");
|
|
7
|
+
const errors_1 = require("../cli/errors");
|
|
8
|
+
/** `axe-auth logout` — best-effort revoke + always clear local. */
|
|
9
|
+
const logoutCommand = {
|
|
10
|
+
name: "logout",
|
|
11
|
+
summary: "Revoke the stored refresh token server-side and clear the local keychain entry.",
|
|
12
|
+
helpText: logout_help_1.HELP_LOGOUT,
|
|
13
|
+
options: {},
|
|
14
|
+
requiresConfig: false,
|
|
15
|
+
async run(_args, deps) {
|
|
16
|
+
const discoverFn = deps.discoverOIDC ?? discoverOIDC_1.discoverOIDC;
|
|
17
|
+
const revokeFn = deps.revokeRefreshToken ?? revokeToken_1.revokeRefreshToken;
|
|
18
|
+
const tokenStore = deps.tokenStore ?? new tokenStore_1.KeyringTokenStore();
|
|
19
|
+
const loaded = deps.loadedEntry ?? (await tokenStore.load());
|
|
20
|
+
if (!loaded.ok) {
|
|
21
|
+
if (loaded.reason === "empty") {
|
|
22
|
+
deps.stdout.write("No stored credentials. Already logged out.\n");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// Corrupt or version-mismatch: there IS a blob, just unusable.
|
|
26
|
+
// Server-side revocation isn't possible without a parseable
|
|
27
|
+
// refresh token, but the local entry must be cleared so the
|
|
28
|
+
// user actually ends up logged out.
|
|
29
|
+
deps.stderr.write(`axe-auth: stored credentials are unusable (${loaded.reason}); clearing local entry without server-side revocation.\n`);
|
|
30
|
+
await clearLocal(tokenStore);
|
|
31
|
+
deps.stdout.write("✓ Logged out.\n");
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const { issuerURL, clientId, allowInsecureIssuer } = loaded.entry;
|
|
35
|
+
// Best-effort server-side revocation. Any failure here is a
|
|
36
|
+
// warning; the local clear runs unconditionally below so the
|
|
37
|
+
// user is "logged out" from this machine regardless.
|
|
38
|
+
if (loaded.entry.tokens.refreshToken) {
|
|
39
|
+
try {
|
|
40
|
+
const config = await discoverFn(issuerURL, { allowInsecureIssuer });
|
|
41
|
+
if (config.revocationEndpoint) {
|
|
42
|
+
await revokeFn({
|
|
43
|
+
revocationEndpoint: config.revocationEndpoint,
|
|
44
|
+
clientId,
|
|
45
|
+
refreshToken: loaded.entry.tokens.refreshToken,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
deps.stderr.write(`axe-auth: authorization server did not advertise a revocation endpoint; refresh token cleared locally only.\n`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
deps.stderr.write(`axe-auth: server-side revocation failed (${(0, errors_1.describeError)(err)}). Continuing with local clear.\n`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
await clearLocal(tokenStore);
|
|
57
|
+
deps.stdout.write("✓ Logged out.\n");
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
async function clearLocal(tokenStore) {
|
|
61
|
+
try {
|
|
62
|
+
await tokenStore.clear();
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
throw new errors_1.CLIError("KEYCHAIN_FAILURE", `Failed to clear stored credentials: ${(0, errors_1.describeError)(err)}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.default = logoutCommand;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getValidAccessToken } from "../oauth/getValidAccessToken";
|
|
2
|
+
import { type TokenStore } from "../oauth/tokenStore";
|
|
3
|
+
import type { CommonArgs } from "../cli/commonArgs";
|
|
4
|
+
import type { CommandDeps } from "../cli/types";
|
|
5
|
+
/** Verb-specific deps for `axe-auth token`. */
|
|
6
|
+
export interface TokenDeps extends CommandDeps {
|
|
7
|
+
/** Override `getValidAccessToken` so tests don't touch the keychain or network. */
|
|
8
|
+
getToken?: typeof getValidAccessToken;
|
|
9
|
+
/** Override the token store. Defaults to a fresh `KeyringTokenStore()`. */
|
|
10
|
+
tokenStore?: TokenStore;
|
|
11
|
+
}
|
|
12
|
+
/** `axe-auth token` — print a currently-valid access token to stdout. */
|
|
13
|
+
declare const tokenCommand: {
|
|
14
|
+
name: string;
|
|
15
|
+
summary: string;
|
|
16
|
+
helpText: string;
|
|
17
|
+
options: {};
|
|
18
|
+
requiresConfig: false;
|
|
19
|
+
run(_args: CommonArgs, deps: TokenDeps): Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
export default tokenCommand;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/** Help text for `axe-auth token --help`. */
|
|
2
|
+
export declare const HELP_TOKEN = "axe-auth token\n\nPrint a currently-valid OAuth access token to stdout, refreshing\nsilently against the stored refresh token if needed.\n\nUsage:\n axe-auth token\n\n Operates exclusively on the keychain entry written by\n `axe-auth login`. The --server / --allow-insecure-issuer /\n --no-allow-insecure-issuer flags are accepted for parity with\n other commands but ignored here; refresh uses the issuer, client,\n and insecure-issuer policy persisted alongside the tokens at login.\n\nOptions:\n --server <url> axe server URL. Used by `login` to fetch\n /api/sso-config and derive the OAuth\n coordinates. Falls back to AXE_SERVER_URL,\n then to https://axe.deque.com (SaaS prod).\n --allow-insecure-issuer Permit non-loopback http URLs (default is\n https only; loopback http is always\n allowed). Applies to `login` only;\n `token` and `logout` use the policy\n persisted at login.\n --no-allow-insecure-issuer\n Force allowInsecureIssuer=false for the new\n `login` (and the entry it persists).\n Ignored by `token` and `logout`.\n Mutually exclusive with\n --allow-insecure-issuer.\n -h, --help Show this help.\n\nOutput:\n The access token is written to stdout with a trailing newline so\n shell substitution (`$(axe-auth token)`) works cleanly. Nothing\n else is written to stdout.\n\nSecurity note:\n Using `$(axe-auth token)` in a shell command exposes the access\n token briefly in the system process-list (observable via `ps` on\n POSIX, Task Manager on Windows). OAuth access tokens are\n short-lived (typically minutes), which limits this exposure\n compared to a static API key, but you should prefer streaming the\n token into a file or env var on platforms where process listings\n are sensitive.\n\nExit codes:\n 0 Success; the token was printed.\n 1 Not authenticated; run `axe-auth login` to re-authenticate.\n 2 Configuration error or transient failure (network, server,\n keychain).";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HELP_TOKEN = void 0;
|
|
4
|
+
const commonArgs_help_1 = require("../cli/commonArgs.help");
|
|
5
|
+
/** Help text for `axe-auth token --help`. */
|
|
6
|
+
exports.HELP_TOKEN = `axe-auth token
|
|
7
|
+
|
|
8
|
+
Print a currently-valid OAuth access token to stdout, refreshing
|
|
9
|
+
silently against the stored refresh token if needed.
|
|
10
|
+
|
|
11
|
+
Usage:
|
|
12
|
+
axe-auth token
|
|
13
|
+
|
|
14
|
+
Operates exclusively on the keychain entry written by
|
|
15
|
+
\`axe-auth login\`. The --server / --allow-insecure-issuer /
|
|
16
|
+
--no-allow-insecure-issuer flags are accepted for parity with
|
|
17
|
+
other commands but ignored here; refresh uses the issuer, client,
|
|
18
|
+
and insecure-issuer policy persisted alongside the tokens at login.
|
|
19
|
+
|
|
20
|
+
Options:
|
|
21
|
+
${commonArgs_help_1.HELP_COMMON_OPTIONS}
|
|
22
|
+
|
|
23
|
+
Output:
|
|
24
|
+
The access token is written to stdout with a trailing newline so
|
|
25
|
+
shell substitution (\`$(axe-auth token)\`) works cleanly. Nothing
|
|
26
|
+
else is written to stdout.
|
|
27
|
+
|
|
28
|
+
Security note:
|
|
29
|
+
Using \`$(axe-auth token)\` in a shell command exposes the access
|
|
30
|
+
token briefly in the system process-list (observable via \`ps\` on
|
|
31
|
+
POSIX, Task Manager on Windows). OAuth access tokens are
|
|
32
|
+
short-lived (typically minutes), which limits this exposure
|
|
33
|
+
compared to a static API key, but you should prefer streaming the
|
|
34
|
+
token into a file or env var on platforms where process listings
|
|
35
|
+
are sensitive.
|
|
36
|
+
|
|
37
|
+
Exit codes:
|
|
38
|
+
0 Success; the token was printed.
|
|
39
|
+
1 Not authenticated; run \`axe-auth login\` to re-authenticate.
|
|
40
|
+
2 Configuration error or transient failure (network, server,
|
|
41
|
+
keychain).`;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const errors_1 = require("../oauth/errors");
|
|
4
|
+
const getValidAccessToken_1 = require("../oauth/getValidAccessToken");
|
|
5
|
+
const tokenStore_1 = require("../oauth/tokenStore");
|
|
6
|
+
const token_help_1 = require("./token.help");
|
|
7
|
+
const errors_2 = require("../cli/errors");
|
|
8
|
+
/** `axe-auth token` — print a currently-valid access token to stdout. */
|
|
9
|
+
const tokenCommand = {
|
|
10
|
+
name: "token",
|
|
11
|
+
summary: "Print a currently-valid access token to stdout, refreshing silently if needed.",
|
|
12
|
+
helpText: token_help_1.HELP_TOKEN,
|
|
13
|
+
options: {},
|
|
14
|
+
requiresConfig: false,
|
|
15
|
+
async run(_args, deps) {
|
|
16
|
+
const getToken = deps.getToken ?? getValidAccessToken_1.getValidAccessToken;
|
|
17
|
+
const tokenStore = deps.tokenStore ?? new tokenStore_1.KeyringTokenStore();
|
|
18
|
+
const loaded = deps.loadedEntry ?? (await tokenStore.load());
|
|
19
|
+
let token;
|
|
20
|
+
try {
|
|
21
|
+
token = await getToken({
|
|
22
|
+
issuerURL: loaded.ok ? loaded.entry.issuerURL : "",
|
|
23
|
+
clientId: loaded.ok ? loaded.entry.clientId : "",
|
|
24
|
+
allowInsecureIssuer: loaded.ok
|
|
25
|
+
? loaded.entry.allowInsecureIssuer
|
|
26
|
+
: false,
|
|
27
|
+
tokenStore,
|
|
28
|
+
loadedEntry: loaded,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
catch (err) {
|
|
32
|
+
if (err instanceof errors_1.OAuthFlowError && err.code === "NOT_AUTHENTICATED") {
|
|
33
|
+
throw new errors_2.CLIError("NOT_AUTHENTICATED", err.message);
|
|
34
|
+
}
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
37
|
+
deps.stdout.write(`${token}\n`);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
exports.default = tokenCommand;
|
package/dist/index.js
CHANGED
|
@@ -1,47 +1,132 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
3
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const node_util_1 = require("node:util");
|
|
5
7
|
const node_fs_1 = require("node:fs");
|
|
6
8
|
const node_path_1 = require("node:path");
|
|
9
|
+
const node_util_1 = require("node:util");
|
|
10
|
+
const commonArgs_1 = require("./cli/commonArgs");
|
|
11
|
+
const tokenStore_1 = require("./oauth/tokenStore");
|
|
12
|
+
const login_1 = __importDefault(require("./commands/login"));
|
|
13
|
+
const logout_1 = __importDefault(require("./commands/logout"));
|
|
14
|
+
const token_1 = __importDefault(require("./commands/token"));
|
|
15
|
+
const errors_1 = require("./cli/errors");
|
|
7
16
|
const pkg = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(__dirname, "..", "package.json"), "utf-8"));
|
|
8
|
-
const
|
|
17
|
+
const COMMANDS = [
|
|
18
|
+
login_1.default,
|
|
19
|
+
logout_1.default,
|
|
20
|
+
token_1.default,
|
|
21
|
+
];
|
|
22
|
+
function findCommand(verb) {
|
|
23
|
+
return COMMANDS.find((c) => c.name === verb);
|
|
24
|
+
}
|
|
25
|
+
function topLevelHelp() {
|
|
26
|
+
const width = Math.max(...COMMANDS.map((c) => c.name.length));
|
|
27
|
+
const verbList = COMMANDS.map((c) => ` ${c.name.padEnd(width)} ${c.summary}`).join("\n");
|
|
28
|
+
return `${pkg.name} v${pkg.version}
|
|
9
29
|
|
|
10
30
|
${pkg.description}
|
|
11
31
|
|
|
12
32
|
Usage:
|
|
13
|
-
axe-auth [options]
|
|
33
|
+
axe-auth <command> [options]
|
|
14
34
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
35
|
+
Commands:
|
|
36
|
+
${verbList}
|
|
37
|
+
|
|
38
|
+
Run \`axe-auth <command> --help\` for command-specific options.
|
|
39
|
+
|
|
40
|
+
Top-level options:
|
|
41
|
+
-v, --version Show version number.
|
|
42
|
+
-h, --help Show this help.`;
|
|
43
|
+
}
|
|
44
|
+
async function dispatch(argv) {
|
|
45
|
+
const [first, ...rest] = argv;
|
|
46
|
+
if (first === undefined || first === "-h" || first === "--help") {
|
|
47
|
+
process.stdout.write(`${topLevelHelp()}\n`);
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
if (first === "-v" || first === "--version") {
|
|
51
|
+
process.stdout.write(`${pkg.version}\n`);
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
if (first.startsWith("-")) {
|
|
55
|
+
process.stderr.write(`Unknown option: ${first}. Run \`axe-auth --help\` for usage.\n`);
|
|
56
|
+
return 2;
|
|
57
|
+
}
|
|
58
|
+
const command = findCommand(first);
|
|
59
|
+
if (!command) {
|
|
60
|
+
process.stderr.write(`Unknown command: ${first}. Run \`axe-auth --help\` for usage.\n`);
|
|
61
|
+
return 2;
|
|
62
|
+
}
|
|
63
|
+
let parsed;
|
|
20
64
|
try {
|
|
21
|
-
|
|
65
|
+
parsed = (0, node_util_1.parseArgs)({
|
|
66
|
+
args: rest,
|
|
22
67
|
options: {
|
|
23
|
-
|
|
68
|
+
...commonArgs_1.COMMON_OPTIONS,
|
|
69
|
+
...command.options,
|
|
24
70
|
help: { type: "boolean", short: "h" },
|
|
25
71
|
},
|
|
26
72
|
strict: true,
|
|
27
|
-
|
|
73
|
+
allowPositionals: false,
|
|
74
|
+
});
|
|
28
75
|
}
|
|
29
76
|
catch (err) {
|
|
30
|
-
|
|
31
|
-
return
|
|
77
|
+
process.stderr.write(`${(0, errors_1.describeError)(err)}\n`);
|
|
78
|
+
return 2;
|
|
32
79
|
}
|
|
33
|
-
if (values.
|
|
34
|
-
|
|
80
|
+
if (parsed.values.help) {
|
|
81
|
+
process.stdout.write(`${command.helpText}\n`);
|
|
35
82
|
return 0;
|
|
36
83
|
}
|
|
37
|
-
|
|
38
|
-
|
|
84
|
+
// Best-effort load: handed to verbs via `deps.loadedEntry` so a
|
|
85
|
+
// single CLI invocation hits the keychain once. Read failure is
|
|
86
|
+
// non-fatal — verbs handle their own empty/corrupt cases.
|
|
87
|
+
let defaults = null;
|
|
88
|
+
let loadedEntry;
|
|
89
|
+
try {
|
|
90
|
+
loadedEntry = await new tokenStore_1.KeyringTokenStore().load();
|
|
91
|
+
if (loadedEntry.ok) {
|
|
92
|
+
defaults = {
|
|
93
|
+
walnutURL: loadedEntry.entry.walnutURL,
|
|
94
|
+
allowInsecureIssuer: loadedEntry.entry.allowInsecureIssuer,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
// Keychain unavailable: leave defaults null. Verbs surface their
|
|
100
|
+
// own clearer errors at the actual save / read site.
|
|
101
|
+
}
|
|
102
|
+
let common;
|
|
103
|
+
try {
|
|
104
|
+
common = (0, commonArgs_1.parseCommonArgs)(parsed.values, process.env, defaults);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
process.stderr.write(`${(0, errors_1.describeError)(err)}\n`);
|
|
108
|
+
return 2;
|
|
109
|
+
}
|
|
110
|
+
const deps = {
|
|
111
|
+
stdin: process.stdin,
|
|
112
|
+
stdout: process.stdout,
|
|
113
|
+
stderr: process.stderr,
|
|
114
|
+
loadedEntry,
|
|
115
|
+
};
|
|
116
|
+
try {
|
|
117
|
+
await command.run({ ...common, ...parsed.values }, deps);
|
|
39
118
|
return 0;
|
|
40
119
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
|
|
120
|
+
catch (err) {
|
|
121
|
+
if (err instanceof errors_1.CLIError) {
|
|
122
|
+
process.stderr.write(`${err.message}\n`);
|
|
123
|
+
return err.exitCode;
|
|
124
|
+
}
|
|
125
|
+
process.stderr.write(`${(0, errors_1.describeError)(err)}\n`);
|
|
126
|
+
return 2;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
dispatch(process.argv.slice(2)).then((code) => process.exit(code), (err) => {
|
|
130
|
+
process.stderr.write(`${err instanceof Error ? (err.stack ?? err.message) : String(err)}\n`);
|
|
46
131
|
process.exit(1);
|
|
47
132
|
});
|
|
@@ -10,12 +10,7 @@ export interface BuildAuthorizationURLOptions {
|
|
|
10
10
|
codeChallenge: string;
|
|
11
11
|
/** CSRF `state` value, echoed by the auth server and validated on callback. */
|
|
12
12
|
state: string;
|
|
13
|
-
/**
|
|
14
|
-
* OAuth scopes to request. No default — callers must choose explicitly.
|
|
15
|
-
* Keycloak-idiomatic value for a refresh-token flow is `["offline_access"]`;
|
|
16
|
-
* Google uses `access_type=offline` (a custom parameter) instead; Auth0
|
|
17
|
-
* tolerates `offline_access` only with specific audience settings.
|
|
18
|
-
*/
|
|
13
|
+
/** OAuth scopes to request. No default; callers choose explicitly. */
|
|
19
14
|
scopes: readonly string[];
|
|
20
15
|
}
|
|
21
16
|
/**
|
|
@@ -2,12 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildAuthorizationURL = buildAuthorizationURL;
|
|
4
4
|
const errors_1 = require("./errors");
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
// something is wrong on the server side (or with the caller's
|
|
8
|
-
// endpoint override) and silently keeping both values would be a
|
|
9
|
-
// security trap: the authorization server's disambiguation is
|
|
10
|
-
// unspecified and varies by implementation.
|
|
5
|
+
// Pre-existing values for these on the authorization endpoint are a
|
|
6
|
+
// security trap: the auth server's disambiguation is unspecified.
|
|
11
7
|
const OAUTH_REQUIRED_PARAMS = [
|
|
12
8
|
"response_type",
|
|
13
9
|
"client_id",
|