@deque/axe-auth 1.8.0-next.f0c366ad → 1.8.0-next.f324ab13

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.
@@ -9,13 +9,26 @@ export interface TokenDeps extends CommandDeps {
9
9
  /** Override the token store. Defaults to a fresh `KeyringTokenStore()`. */
10
10
  tokenStore?: TokenStore;
11
11
  }
12
+ /** Arguments for `axe-auth token`. */
13
+ export interface TokenArgs extends CommonArgs {
14
+ /**
15
+ * Undocumented on purpose: only the axe MCP server reads it (#1448). The
16
+ * server accepts axe-auth from its own release version up, so this shape may
17
+ * only gain fields until the next major version.
18
+ */
19
+ json?: boolean;
20
+ }
12
21
  /** `axe-auth token` — print a currently-valid access token to stdout. */
13
22
  declare const tokenCommand: {
14
23
  name: string;
15
24
  summary: string;
16
25
  helpText: string;
17
- options: {};
26
+ options: {
27
+ json: {
28
+ type: "boolean";
29
+ };
30
+ };
18
31
  requiresConfig: false;
19
- run(_args: CommonArgs, deps: TokenDeps): Promise<void>;
32
+ run(args: TokenArgs, deps: TokenDeps): Promise<void>;
20
33
  };
21
34
  export default tokenCommand;
@@ -10,9 +10,9 @@ const tokenCommand = {
10
10
  name: "token",
11
11
  summary: "Print a currently-valid access token to stdout, refreshing silently if needed.",
12
12
  helpText: token_help_1.HELP_TOKEN,
13
- options: {},
13
+ options: { json: { type: "boolean" } },
14
14
  requiresConfig: false,
15
- async run(_args, deps) {
15
+ async run(args, deps) {
16
16
  const getToken = deps.getToken ?? getValidAccessToken_1.getValidAccessToken;
17
17
  const tokenStore = deps.tokenStore ?? new tokenStore_1.KeyringTokenStore();
18
18
  const loaded = deps.loadedEntry ?? (await tokenStore.load());
@@ -34,6 +34,13 @@ const tokenCommand = {
34
34
  }
35
35
  throw err;
36
36
  }
37
+ if (args.json && loaded.ok) {
38
+ // Named for the user-facing `--server` / AXE_SERVER_URL, not the
39
+ // internal codename the stored entry uses.
40
+ const serverURL = loaded.entry.walnutURL;
41
+ deps.stdout.write(`${JSON.stringify({ accessToken: token, serverURL })}\n`);
42
+ return;
43
+ }
37
44
  deps.stdout.write(`${token}\n`);
38
45
  },
39
46
  };
@@ -42,13 +42,11 @@ export interface GetValidAccessTokenOptions {
42
42
  * Throws `OAuthFlowError("DISCOVERY_FAILED", ...)` when the issuer
43
43
  * URL cannot be reached or parsed at refresh time.
44
44
  *
45
- * **Concurrency note.** Not safe against parallel invocations for
46
- * the same issuer. Keycloak rotates refresh tokens by default; if
47
- * two parallel calls both land on the refresh path, only one
48
- * winner's rotated refresh token will be persisted and the loser's
49
- * rotated token is stranded. The intended consumer is the
50
- * `axe-auth token` CLI (a one-shot), so this is fine in context;
51
- * per-request callers should wrap in an in-flight-Promise singleton
52
- * keyed by issuer.
45
+ * **Concurrency note.** Parallel invocations for the same issuer each
46
+ * refresh with the same stored refresh token. Deque's Keycloak realms
47
+ * accept a used refresh token again, so both succeed and the last save
48
+ * wins. A realm with "Revoke Refresh Token" on rejects the second
49
+ * refresh and ends the session, so per-request callers should still
50
+ * wrap this in an in-flight-Promise singleton keyed by issuer.
53
51
  */
54
52
  export declare function getValidAccessToken(options: GetValidAccessTokenOptions): Promise<string>;
@@ -42,14 +42,12 @@ function notAuthenticated(message, cause) {
42
42
  * Throws `OAuthFlowError("DISCOVERY_FAILED", ...)` when the issuer
43
43
  * URL cannot be reached or parsed at refresh time.
44
44
  *
45
- * **Concurrency note.** Not safe against parallel invocations for
46
- * the same issuer. Keycloak rotates refresh tokens by default; if
47
- * two parallel calls both land on the refresh path, only one
48
- * winner's rotated refresh token will be persisted and the loser's
49
- * rotated token is stranded. The intended consumer is the
50
- * `axe-auth token` CLI (a one-shot), so this is fine in context;
51
- * per-request callers should wrap in an in-flight-Promise singleton
52
- * keyed by issuer.
45
+ * **Concurrency note.** Parallel invocations for the same issuer each
46
+ * refresh with the same stored refresh token. Deque's Keycloak realms
47
+ * accept a used refresh token again, so both succeed and the last save
48
+ * wins. A realm with "Revoke Refresh Token" on rejects the second
49
+ * refresh and ends the session, so per-request callers should still
50
+ * wrap this in an in-flight-Promise singleton keyed by issuer.
53
51
  */
54
52
  async function getValidAccessToken(options) {
55
53
  const { issuerURL, clientId, expiryBufferMs = DEFAULT_EXPIRY_BUFFER_MS, tokenStore = new tokenStore_1.KeyringTokenStore(), loadedEntry, signal, allowInsecureIssuer, onWarning = defaultOnWarning, now = Date.now, } = options;
@@ -110,12 +108,11 @@ async function getValidAccessToken(options) {
110
108
  // retry without re-logging-in.
111
109
  throw err;
112
110
  }
113
- // HAZARD: Keycloak (and most rotating-refresh-token providers) have
114
- // already consumed the old refresh token server-side by the time
115
- // `refreshTokens` returns. If persisting the rotated set fails
116
- // here, we hold a valid access token in memory but the stored
117
- // refresh token is now stale — the next invocation will POST it,
118
- // get `invalid_grant`, and prompt re-authentication.
111
+ // HAZARD: if persisting the new set fails, the store keeps the old
112
+ // refresh token. Deque's Keycloak realms accept a used refresh token
113
+ // again, so the next invocation still refreshes; a realm with "Revoke
114
+ // Refresh Token" on rejects it with `invalid_grant`, and the user has
115
+ // to log in again.
119
116
  //
120
117
  // We still return the fresh access token so the current call is
121
118
  // useful, and warn the caller so "why does the next run need me to
@@ -130,7 +127,7 @@ async function getValidAccessToken(options) {
130
127
  });
131
128
  }
132
129
  catch (err) {
133
- onWarning(`Refreshed tokens could not be saved: ${err instanceof Error ? err.message : String(err)}. The current call will succeed, but the next invocation will require re-authentication.`);
130
+ onWarning(`Refreshed tokens could not be saved: ${err instanceof Error ? err.message : String(err)}. The current call will succeed, but the next invocation may require re-authentication.`);
134
131
  }
135
132
  return fresh.accessToken;
136
133
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deque/axe-auth",
3
- "version": "1.8.0-next.f0c366ad",
3
+ "version": "1.8.0-next.f324ab13",
4
4
  "description": "CLI authentication utility for Deque services",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "repository": {