passport-bridge 0.11.1 → 0.11.3
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/cliLogin.js +93 -40
- package/dist/cliOutput.js +1 -1
- package/dist/cliSetup.js +2 -0
- 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/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/cliSetup.js
CHANGED
|
@@ -100,6 +100,8 @@ export async function setup(args, runtime, withGateway, install = runManagedSkil
|
|
|
100
100
|
const response = await gateway.fetchApi(path, { signal: runtime.signal, redirect: "error" });
|
|
101
101
|
if (!response.ok) {
|
|
102
102
|
await response.body?.cancel().catch(() => undefined);
|
|
103
|
+
if (response.status === 402)
|
|
104
|
+
return failure("Team setups aren't available on this workspace's plan.", 1, "setup_unavailable");
|
|
103
105
|
if (response.status === 404)
|
|
104
106
|
return failure("This setup is unavailable, or the gateway needs an update. Refresh your assigned setups in Passport.", 1, "setup_unavailable");
|
|
105
107
|
return failure("Passport could not authorize this employee setup. Reconnect or check your assignment.", response.status === 401 || response.status === 403 ? 2 : 1, "setup_unavailable");
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.11.
|
|
1
|
+
export declare const VERSION = "0.11.3";
|
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.3",
|
|
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.3",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@modelcontextprotocol/sdk": "1.30.0"
|