passport-bridge 0.11.0 → 0.11.2
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 +1 -0
- package/dist/bridgeExchange.js +5 -1
- package/dist/cliHook.d.ts +2 -0
- package/dist/cliHook.js +14 -9
- package/dist/cliLogin.js +93 -40
- package/dist/cliOutput.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ passport run github_search_issues '{"query":"SSO"}'
|
|
|
26
26
|
```
|
|
27
27
|
|
|
28
28
|
- `--workspace` alone signs in to Passport Cloud. Self-hosted: add `--cloud https://passport.example.com` (origin only).
|
|
29
|
+
- Re-signing in? Bare `passport login` reuses the workspace of the active profile, the sole CLI profile, or the one workspace all saved profiles share. With several workspaces saved it lists them and asks for `--workspace`.
|
|
29
30
|
- `--no-open` (or `PASSPORT_NO_OPEN=1`) prints the device URL instead of opening a browser. Use it over SSH and in headless sessions.
|
|
30
31
|
- Remote servers must use HTTPS. Plain HTTP works only on `localhost`, `127.0.0.0/8`, or `::1`.
|
|
31
32
|
- Requires a gateway reporting serverInfo `passport` 0.5.0 or newer with the four-tool CLI protocol; older servers fail before any tool call.
|
package/dist/bridgeExchange.js
CHANGED
|
@@ -354,7 +354,11 @@ export class TokenManager {
|
|
|
354
354
|
return this.refusedExchange(res, presented);
|
|
355
355
|
const data = await this.readExchange(res);
|
|
356
356
|
this.fallbackRotation = undefined;
|
|
357
|
-
|
|
357
|
+
// A non-rotating manager never keeps a child. The server still mints one
|
|
358
|
+
// when the presented token is a parent a peer rotated moments ago (an
|
|
359
|
+
// in-grace sibling); it stays unused and the server retires it as soon as
|
|
360
|
+
// the family's live child is exchanged.
|
|
361
|
+
if (data.refreshToken && data.refreshToken !== presented && this.onRotate) {
|
|
358
362
|
this.assertHomeWorkspace(data.refreshToken);
|
|
359
363
|
this.pendingRotation = {
|
|
360
364
|
previous: presented,
|
package/dist/cliHook.d.ts
CHANGED
|
@@ -42,6 +42,8 @@ export type HookInput = {
|
|
|
42
42
|
export type HookDependencies = {
|
|
43
43
|
/** Deliver one report. The default posts it to the signed-in workspace. */
|
|
44
44
|
send?: (report: CliHookReport, signal: AbortSignal, runtime: Runtime, args: ParsedArgs) => Promise<void>;
|
|
45
|
+
/** Network seam for the default delivery. */
|
|
46
|
+
fetch?: typeof fetch;
|
|
45
47
|
};
|
|
46
48
|
/** Keep the shape of the verb, never its arguments: anything that could carry a
|
|
47
49
|
* path, an endpoint, or a value is dropped rather than truncated. */
|
package/dist/cliHook.js
CHANGED
|
@@ -134,17 +134,19 @@ async function readStdin(runtime) {
|
|
|
134
134
|
return Buffer.concat(chunks).toString("utf8");
|
|
135
135
|
}
|
|
136
136
|
/** Post one report with the same credential `passport discover` uses. Agent
|
|
137
|
-
* keys are deliberately unsupported: a hook reports a person's own shell.
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
* keys are deliberately unsupported: a hook reports a person's own shell.
|
|
138
|
+
*
|
|
139
|
+
* The exchange never rotates the refresh token. The hook runs once per shell
|
|
140
|
+
* command under a 1.5 s budget, and a rotation cut short by that budget would
|
|
141
|
+
* lose the only copy of the new token, which later revokes the whole family.
|
|
142
|
+
* With nothing to rotate there is nothing to serialize either, so the hook
|
|
143
|
+
* never takes the profile lease or queues behind a serving bridge. */
|
|
144
|
+
async function postReport(report, signal, args, env, fetcher) {
|
|
145
|
+
const auth = resolveCliAuth(args, env);
|
|
140
146
|
if (auth.kind !== "profile")
|
|
141
147
|
return;
|
|
142
148
|
const { TokenManager } = await import("./bridge.js");
|
|
143
|
-
const
|
|
144
|
-
const manager = new TokenManager(auth.endpoint, auth.refreshToken, (next, previous) => persistCurrentProfileRotation(auth.profile, previous, next, auth.endpoint), {
|
|
145
|
-
reload: () => recoverProfileRotation(auth.profile)?.refreshToken,
|
|
146
|
-
lock: (fn) => withProfileLock(auth.profile, fn)
|
|
147
|
-
}, HOOK_BUDGET_MS, signal);
|
|
149
|
+
const manager = new TokenManager(auth.endpoint, auth.refreshToken, undefined, undefined, HOOK_BUDGET_MS, signal, fetcher);
|
|
148
150
|
const response = await manager.authedFetch(`${new URL(auth.endpoint).origin}${CLI_ACTIVITY_PATH}`, {
|
|
149
151
|
method: "POST",
|
|
150
152
|
headers: { "content-type": "application/json", "x-passport-surface": "cli" },
|
|
@@ -178,7 +180,10 @@ async function runHook(args, runtime, deps) {
|
|
|
178
180
|
if (!report)
|
|
179
181
|
return;
|
|
180
182
|
const budget = AbortSignal.any([runtime.signal, AbortSignal.timeout(HOOK_BUDGET_MS)]);
|
|
181
|
-
|
|
183
|
+
if (deps.send)
|
|
184
|
+
await deps.send(report, budget, runtime, args);
|
|
185
|
+
else
|
|
186
|
+
await postReport(report, budget, args, runtime.env, deps.fetch ?? fetch);
|
|
182
187
|
}
|
|
183
188
|
export async function hook(args, runtime, deps = {}) {
|
|
184
189
|
const action = args.positionals[0];
|
package/dist/cliLogin.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import { workspaceOfToken } from "./tokenWorkspace.js";
|
|
3
3
|
import { bool, value } from "./cliArgs.js";
|
|
4
|
-
import { assertCredentialStoreMutationReady, credsPath, getProfile, getProfileStrict,
|
|
5
|
-
import { cloudOrigin, endpoint, failure, openUrl, profileName, readBoundedJson, safeApiError, sameOriginWebUrl, sleep, timedFetch, timeoutMs } from "./cliSupport.js";
|
|
4
|
+
import { assertCredentialStoreMutationReady, credsPath, getProfile, getProfileStrict, readCreds, setActiveProfile, withProfileLock, writeProfile } from "./credentials.js";
|
|
5
|
+
import { cloudOrigin, endpoint, failure, openUrl, profileName, readBoundedJson, safeApiError, sameOriginWebUrl, selectStoredProfile, sleep, timedFetch, timeoutMs } from "./cliSupport.js";
|
|
6
6
|
const PASSPORT_CLOUD = "https://passportmcp.com";
|
|
7
7
|
function workspaceFromEndpoint(raw) {
|
|
8
8
|
try {
|
|
@@ -14,8 +14,70 @@ function workspaceFromEndpoint(raw) {
|
|
|
14
14
|
return "";
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
+
/** A saved profile's workspace comes from its endpoint path or its
|
|
18
|
+
* server-issued token prefix, never from the user-chosen profile name. */
|
|
19
|
+
function workspaceOfProfile(profile) {
|
|
20
|
+
return workspaceFromEndpoint(profile.endpoint) || workspaceOfToken(profile.refreshToken);
|
|
21
|
+
}
|
|
22
|
+
function originOfProfile(profile) {
|
|
23
|
+
try {
|
|
24
|
+
return new URL(endpoint(profile.endpoint)).origin;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return "";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/** Distinct workspaces across saved profiles, limited to `cloud` when one was
|
|
31
|
+
* requested. A profile with an unreadable workspace or origin leaves the set
|
|
32
|
+
* incomplete, so it can never be treated as the only choice. */
|
|
33
|
+
function storedWorkspaces(creds, cloud) {
|
|
34
|
+
const found = new Map();
|
|
35
|
+
let complete = true;
|
|
36
|
+
for (const profile of Object.values(creds)) {
|
|
37
|
+
const origin = originOfProfile(profile);
|
|
38
|
+
if (cloud && origin && origin !== cloud)
|
|
39
|
+
continue;
|
|
40
|
+
const workspace = workspaceOfProfile(profile);
|
|
41
|
+
if (!origin || !workspace) {
|
|
42
|
+
complete = false;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
found.set(`${origin} ${workspace}`, { workspace, cloud: origin });
|
|
46
|
+
}
|
|
47
|
+
const candidates = [...found.values()].sort((a, b) => a.cloud.localeCompare(b.cloud) || a.workspace.localeCompare(b.workspace));
|
|
48
|
+
return { candidates, complete };
|
|
49
|
+
}
|
|
50
|
+
function loginArgv(workspace, cloud) {
|
|
51
|
+
return [
|
|
52
|
+
"passport",
|
|
53
|
+
"login",
|
|
54
|
+
"--workspace",
|
|
55
|
+
workspace,
|
|
56
|
+
...(cloud && cloud !== PASSPORT_CLOUD ? ["--cloud", cloud] : [])
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
function missingWorkspace(cloud) {
|
|
60
|
+
return failure(`Passport needs a workspace id to sign in. Run: ${loginArgv("<ws_id>", cloud).join(" ")}`, 6, "usage", {
|
|
61
|
+
hint: cloud
|
|
62
|
+
? "Ask your admin for the workspace id."
|
|
63
|
+
: "Ask your admin for the workspace id. For self-hosted Passport, also pass --cloud <origin>.",
|
|
64
|
+
requiredInput: ["workspace-id"]
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
function ambiguousWorkspace(candidates, complete) {
|
|
68
|
+
const lines = candidates.map(({ workspace, cloud }) => `${workspace} on ${cloud}: ${loginArgv(workspace, cloud).join(" ")}`);
|
|
69
|
+
if (!complete)
|
|
70
|
+
lines.push("Some saved profiles do not record a workspace id.");
|
|
71
|
+
return failure("Saved profiles do not identify a single workspace. Choose one with --workspace.", 6, "usage", {
|
|
72
|
+
hint: lines.join("\n"),
|
|
73
|
+
requiredInput: ["workspace-id"],
|
|
74
|
+
next: candidates.map(({ workspace, cloud }) => ({
|
|
75
|
+
argv: loginArgv(workspace, cloud),
|
|
76
|
+
description: `Sign in to workspace ${workspace} on ${cloud}.`
|
|
77
|
+
}))
|
|
78
|
+
});
|
|
79
|
+
}
|
|
17
80
|
function loginOptions(args, runtime) {
|
|
18
|
-
const explicitProfile = value(args, "profile");
|
|
19
81
|
const workspaceOption = value(args, "workspace");
|
|
20
82
|
const explicitWorkspace = workspaceOption !== undefined;
|
|
21
83
|
const workspaceFromOption = workspaceOption?.trim() ?? "";
|
|
@@ -23,55 +85,42 @@ function loginOptions(args, runtime) {
|
|
|
23
85
|
return failure("--workspace must be a valid workspace id.", 6, "usage");
|
|
24
86
|
}
|
|
25
87
|
const creds = readCreds();
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
: explicitWorkspace
|
|
33
|
-
? `cli@${workspaceFromOption}`
|
|
34
|
-
: active && creds[active]
|
|
35
|
-
? active
|
|
36
|
-
: names.length === 1
|
|
37
|
-
? names[0]
|
|
38
|
-
: "";
|
|
88
|
+
// --profile and PASSPORT_PROFILE always win. Otherwise --workspace names the
|
|
89
|
+
// CLI profile to refresh; without it, login refreshes the profile other
|
|
90
|
+
// commands would use (active, then the sole CLI profile, then the sole profile).
|
|
91
|
+
const selection = selectStoredProfile(args, runtime.env, creds);
|
|
92
|
+
const namedBySelector = selection.source === "explicit" || selection.source === "environment";
|
|
93
|
+
const requestedProfile = explicitWorkspace && !namedBySelector ? `cli@${workspaceFromOption}` : (selection.profile ?? "");
|
|
39
94
|
const existing = requestedProfile ? getProfile(requestedProfile) : undefined;
|
|
40
95
|
if (explicitWorkspace && existing) {
|
|
41
|
-
const existingWorkspace =
|
|
96
|
+
const existingWorkspace = workspaceOfProfile(existing);
|
|
42
97
|
if (!existingWorkspace || existingWorkspace !== workspaceFromOption) {
|
|
43
98
|
return failure(`Profile "${requestedProfile}" belongs to another workspace and will not be overwritten. Choose a new --profile name.`, 6, "usage");
|
|
44
99
|
}
|
|
45
100
|
}
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (!
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
description: `Select the saved profile "${name}" to refresh.`
|
|
60
|
-
}))
|
|
61
|
-
]
|
|
62
|
-
});
|
|
101
|
+
const cloudOption = value(args, "cloud") || runtime.env.PASSPORT_CLOUD || "";
|
|
102
|
+
const requestedCloud = cloudOption ? cloudOrigin(cloudOption) : "";
|
|
103
|
+
let workspace = explicitWorkspace ? workspaceFromOption : existing ? workspaceOfProfile(existing) : "";
|
|
104
|
+
let cloud = requestedCloud || (existing ? new URL(endpoint(existing.endpoint)).origin : workspace ? PASSPORT_CLOUD : "");
|
|
105
|
+
if (!workspace && !requestedProfile) {
|
|
106
|
+
// No profile is selected: use the one workspace saved profiles share, and
|
|
107
|
+
// never pick between several.
|
|
108
|
+
const { candidates, complete } = storedWorkspaces(creds, requestedCloud);
|
|
109
|
+
if (candidates.length === 1 && complete) {
|
|
110
|
+
({ workspace, cloud } = candidates[0]);
|
|
111
|
+
}
|
|
112
|
+
else if (candidates.length) {
|
|
113
|
+
return ambiguousWorkspace(candidates, complete);
|
|
63
114
|
}
|
|
64
|
-
return failure("Tell Passport which workspace to sign in to.", 6, "usage", {
|
|
65
|
-
hint: `Run: passport login --workspace <workspace-id>\nFor self-hosted Passport, also pass --cloud <origin>.`,
|
|
66
|
-
requiredInput: ["workspace-id"]
|
|
67
|
-
});
|
|
68
115
|
}
|
|
116
|
+
if (!cloud)
|
|
117
|
+
return missingWorkspace("");
|
|
69
118
|
const clientOption = value(args, "client");
|
|
70
119
|
const client = clientOption === undefined ? existing?.client || "cli" : clientOption.trim();
|
|
71
120
|
if (!/^[A-Za-z0-9._-]{1,40}$/.test(client)) {
|
|
72
121
|
return failure("--client must be a valid client id (1-40 characters).", 6, "usage");
|
|
73
122
|
}
|
|
74
|
-
return { requestedProfile, cloud: cloudOrigin(
|
|
123
|
+
return { requestedProfile, cloud: cloudOrigin(cloud), workspace, client };
|
|
75
124
|
}
|
|
76
125
|
async function waitForDeviceApproval(cloud, code, args, runtime) {
|
|
77
126
|
const deadlineAt = Date.now() + 10 * 60 * 1000;
|
|
@@ -98,7 +147,11 @@ export async function login(args, runtime) {
|
|
|
98
147
|
const workspaceQuery = workspace ? `?ws=${encodeURIComponent(workspace)}` : "";
|
|
99
148
|
const start = await timedFetch(`${cloud}/api/auth/device/start${workspaceQuery}`, { method: "POST" }, timeoutMs(args), runtime.signal);
|
|
100
149
|
if (start.status === 404) {
|
|
101
|
-
|
|
150
|
+
if (!workspace)
|
|
151
|
+
return missingWorkspace(cloud);
|
|
152
|
+
return failure("Passport could not find that workspace. Ask your admin for its workspace id.", 2, "auth", {
|
|
153
|
+
hint: `Then run: ${loginArgv("<ws_id>", cloud).join(" ")}`
|
|
154
|
+
});
|
|
102
155
|
}
|
|
103
156
|
if (!start.ok)
|
|
104
157
|
return failure(`Could not start sign-in (${start.status}).`, 1, "server");
|
package/dist/cliOutput.js
CHANGED
|
@@ -4,7 +4,7 @@ import { CliFailure, sanitize } from "./cliSupport.js";
|
|
|
4
4
|
import { VERSION } from "./version.js";
|
|
5
5
|
function helpText(verb) {
|
|
6
6
|
const details = {
|
|
7
|
-
login: "passport login [--workspace <id>] [--cloud <origin>] [--client <id>] [--profile <name>] [--no-open]\nStarts device sign-in, stores a cli-surface rotating credential, and makes that profile active. Passport Cloud is used when --workspace is provided without --cloud.",
|
|
7
|
+
login: "passport login [--workspace <id>] [--cloud <origin>] [--client <id>] [--profile <name>] [--no-open]\nStarts device sign-in, stores a cli-surface rotating credential, and makes that profile active. Passport Cloud is used when --workspace is provided without --cloud. Without --workspace, login reuses the workspace and cloud of the saved profile it refreshes, or the one workspace all saved profiles share; it never chooses between several.",
|
|
8
8
|
logout: "passport logout [--profile <name>]\nRevokes the rotating credential and always removes the local profile.",
|
|
9
9
|
profiles: "passport profiles\nLists saved profiles and marks the active profile. Works offline.",
|
|
10
10
|
use: "passport use <name>\nSelects a saved profile as the default for subsequent commands. Works offline.",
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.11.
|
|
1
|
+
export declare const VERSION = "0.11.2";
|
package/dist/version.js
CHANGED
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "passport-bridge",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.2",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "passport-bridge",
|
|
9
|
-
"version": "0.11.
|
|
9
|
+
"version": "0.11.2",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@modelcontextprotocol/sdk": "1.30.0"
|