@lizard-build/cli 4.0.33 → 4.0.35
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 +5 -0
- package/dist/commands/billing.d.ts +1 -0
- package/dist/commands/billing.js +1 -1
- package/dist/commands/billing.js.map +1 -1
- package/dist/commands/login.d.ts +17 -26
- package/dist/commands/login.js +207 -69
- package/dist/commands/login.js.map +1 -1
- package/dist/lib/auth.d.ts +19 -8
- package/dist/lib/auth.js +38 -67
- package/dist/lib/auth.js.map +1 -1
- package/dist/lib/config.d.ts +2 -0
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/signin.d.ts +91 -0
- package/dist/lib/signin.js +249 -0
- package/dist/lib/signin.js.map +1 -0
- package/dist/lib/skills-data.generated.js +1 -1
- package/dist/lib/skills-data.generated.js.map +1 -1
- package/dist/lib/updater.d.ts +1 -1
- package/dist/lib/updater.js +1 -1
- package/install.cmd +15 -2
- package/install.ps1 +14 -2
- package/install.sh +22 -2
- package/package.json +1 -1
- package/skill-data/core/SKILL.md +14 -5
- package/src/commands/billing.ts +1 -1
- package/src/commands/login.ts +247 -92
- package/src/lib/auth.ts +41 -71
- package/src/lib/config.ts +2 -0
- package/src/lib/signin.ts +320 -0
- package/src/lib/updater.ts +1 -1
- package/test/unit/json.test.ts +3 -0
- package/test/unit/login.test.ts +398 -0
package/dist/lib/auth.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import open from "open";
|
|
2
|
-
import
|
|
2
|
+
import { isJSONMode } from "./format.js";
|
|
3
3
|
import { loadConfig, saveConfig, } from "./config.js";
|
|
4
4
|
/**
|
|
5
5
|
* The env var carrying a token or a `liz_` API key. LIZARD_TOKEN is the
|
|
@@ -44,6 +44,28 @@ export function clearPendingAuth() {
|
|
|
44
44
|
export function isLoggedIn() {
|
|
45
45
|
return getToken() !== null;
|
|
46
46
|
}
|
|
47
|
+
/** The token a command would use right now, or null when a sign-in is needed. */
|
|
48
|
+
export function validToken() {
|
|
49
|
+
const fromEnv = envToken();
|
|
50
|
+
if (fromEnv)
|
|
51
|
+
return fromEnv;
|
|
52
|
+
const creds = loadCredentials();
|
|
53
|
+
return creds && !isExpired(creds) ? creds.accessToken : null;
|
|
54
|
+
}
|
|
55
|
+
/** Store what an approved CLI session returned, and drop the pending session. */
|
|
56
|
+
export function saveSessionLogin(result) {
|
|
57
|
+
const expMs = jwtExpiryMs(result.accessToken);
|
|
58
|
+
saveCredentials({
|
|
59
|
+
accessToken: result.accessToken,
|
|
60
|
+
expiresAt: expMs ? new Date(expMs).toISOString() : undefined,
|
|
61
|
+
userId: result.user.id,
|
|
62
|
+
username: result.user.username,
|
|
63
|
+
email: result.user.email,
|
|
64
|
+
avatarUrl: result.user.avatarUrl,
|
|
65
|
+
});
|
|
66
|
+
clearPendingAuth();
|
|
67
|
+
return loadCredentials();
|
|
68
|
+
}
|
|
47
69
|
function isTTY() {
|
|
48
70
|
return Boolean(process.stdout.isTTY);
|
|
49
71
|
}
|
|
@@ -74,14 +96,13 @@ function isExpired(creds) {
|
|
|
74
96
|
/**
|
|
75
97
|
* Ensure the user is authenticated.
|
|
76
98
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
* in the
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* the
|
|
83
|
-
*
|
|
84
|
-
* expired, starts a fresh one.
|
|
99
|
+
* A token from the environment or a saved login that has not expired wins.
|
|
100
|
+
* Otherwise a session the browser already approved finishes here. Failing
|
|
101
|
+
* that, a person at a terminal signs in on the spot (pick GitHub or Google,
|
|
102
|
+
* the browser opens, the CLI waits) and the command carries on. Anything else
|
|
103
|
+
* (an agent, a pipe, --json) gets a NOT_AUTHENTICATED error whose body holds
|
|
104
|
+
* the sign-in links; once the user approves, the same command run again
|
|
105
|
+
* picks the session up.
|
|
85
106
|
*/
|
|
86
107
|
export async function requireAuth() {
|
|
87
108
|
const fromEnv = envToken();
|
|
@@ -91,65 +112,15 @@ export async function requireAuth() {
|
|
|
91
112
|
const creds = loadCredentials();
|
|
92
113
|
if (creds && !isExpired(creds))
|
|
93
114
|
return creds;
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const expMs = jwtExpiryMs(result.accessToken);
|
|
102
|
-
saveCredentials({
|
|
103
|
-
accessToken: result.accessToken,
|
|
104
|
-
expiresAt: expMs ? new Date(expMs).toISOString() : undefined,
|
|
105
|
-
userId: result.user.id,
|
|
106
|
-
username: result.user.username,
|
|
107
|
-
email: result.user.email,
|
|
108
|
-
avatarUrl: result.user.avatarUrl,
|
|
109
|
-
});
|
|
110
|
-
clearPendingAuth();
|
|
111
|
-
return loadCredentials();
|
|
112
|
-
}
|
|
113
|
-
if (result.status === "expired") {
|
|
114
|
-
clearPendingAuth();
|
|
115
|
-
// Fall through to start a fresh session below
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
// Still pending — user hasn't authenticated yet
|
|
119
|
-
printAuthPrompt(pending.authUrl);
|
|
120
|
-
process.exit(0);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
catch {
|
|
124
|
-
// Network error — assume still pending, show URL
|
|
125
|
-
printAuthPrompt(pending.authUrl);
|
|
126
|
-
process.exit(0);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
// No credentials and no pending session — need to start a new auth flow
|
|
130
|
-
if (!isTTY()) {
|
|
131
|
-
const err = new Error(creds
|
|
132
|
-
? "Session expired. Run `lizard login` again or set LIZARD_TOKEN / LIZARD_API_KEY."
|
|
133
|
-
: "Not authenticated. Set LIZARD_TOKEN (or LIZARD_API_KEY) or run `lizard login` first.");
|
|
134
|
-
err.code = "NOT_AUTHENTICATED";
|
|
135
|
-
throw err;
|
|
115
|
+
const signin = await import("./signin.js");
|
|
116
|
+
const resumed = await signin.resumePending();
|
|
117
|
+
if (resumed.kind === "complete")
|
|
118
|
+
return loadCredentials();
|
|
119
|
+
if (isTTY() && !isJSONMode()) {
|
|
120
|
+
await signin.signInInteractive();
|
|
121
|
+
return loadCredentials();
|
|
136
122
|
}
|
|
137
|
-
|
|
138
|
-
const { getBaseURL } = await import("./api.js");
|
|
139
|
-
const session = await createSession();
|
|
140
|
-
const authUrl = `${getBaseURL()}/auth/cli?session=${session.sessionId}`;
|
|
141
|
-
savePendingAuth({
|
|
142
|
-
sessionId: session.sessionId,
|
|
143
|
-
sessionSecret: session.sessionSecret,
|
|
144
|
-
authUrl,
|
|
145
|
-
createdAt: Date.now(),
|
|
146
|
-
});
|
|
147
|
-
await openURL(authUrl);
|
|
148
|
-
printAuthPrompt(authUrl);
|
|
149
|
-
process.exit(0);
|
|
150
|
-
}
|
|
151
|
-
function printAuthPrompt(authUrl) {
|
|
152
|
-
process.stderr.write(`\nAuthenticate with Lizard:\n ${chalk.cyan(authUrl)}\n\nThen run your command again.\n\n`);
|
|
123
|
+
throw await signin.loginRequiredError(resumed, Boolean(creds));
|
|
153
124
|
}
|
|
154
125
|
/** Open a URL in the default browser, or print it if headless. */
|
|
155
126
|
export async function openURL(url) {
|
package/dist/lib/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/lib/auth.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,UAAU,EACV,UAAU,GAGX,MAAM,aAAa,CAAC;AAIrB;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,IAAI,C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AAM,MAAM,CAAC,kBAAkB,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AACjE,CAAC;AAED,kEAAkE;AAClE,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,GAAW;IACvC,MAAM,KAAK,GAAG,OAAO,CACnB,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,CAC5E,CAAC;IACF,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACrC,MAAM,SAAS,GACb,OAAO,CAAC,QAAQ,KAAK,OAAO;QAC5B,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO;QACpB,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;IAE/B,IAAI,KAAK,IAAI,IAAI,IAAI,SAAS,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC;QACH,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/dist/lib/config.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export interface PendingAuth {
|
|
|
27
27
|
sessionSecret: string;
|
|
28
28
|
authUrl: string;
|
|
29
29
|
createdAt: number;
|
|
30
|
+
/** When the platform drops the session. Older CLIs did not save it. */
|
|
31
|
+
expiresAt?: number;
|
|
30
32
|
}
|
|
31
33
|
export interface Config {
|
|
32
34
|
credentials?: Credentials;
|
package/dist/lib/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/lib/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,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DAA8D;IAC9D,EAAE;IACF,qFAAqF;IACrF,wEAAwE;IACxE,IAAI,qBAAqB,CAAC,IAAI,CAAC,SAAS,CAAC;QAAE,OAAO,SAAS,CAAC;IAC5D,OAAO,oBAAoB,CAAC,SAAS,CAAC,CAAC;AACzC,CAAC;AAED,wFAAwF;AACxF,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,SAAiB;IAC1D,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;IACzC,MAAM,QAAQ,GAAG,MAAM,GAAG,CAAC,GAAG,CAAoD,eAAe,CAAC,CAAC;IACnG,sEAAsE;IACtE,MAAM,KAAK,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;IACtC,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CACzB,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,KAAK;QAC5B,CAAC,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,KAAK;QAC/B,CAAC,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,KAAK,CAClC,CAAC;IACF,IAAI,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,YAAY,SAAS,cAAc,CAAC,CAAC;IACjE,OAAO,KAAK,CAAC,EAAE,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { APIError } from "./api.js";
|
|
2
|
+
/** The sign-in methods the /auth/cli page can send a person to. */
|
|
3
|
+
export type AuthProvider = "github" | "google";
|
|
4
|
+
export declare const AUTH_PROVIDERS: AuthProvider[];
|
|
5
|
+
interface SessionResponse {
|
|
6
|
+
sessionId: string;
|
|
7
|
+
sessionSecret: string;
|
|
8
|
+
expiresIn: number;
|
|
9
|
+
}
|
|
10
|
+
export interface CheckResponse {
|
|
11
|
+
status: "pending" | "complete" | "expired";
|
|
12
|
+
accessToken?: string;
|
|
13
|
+
user?: {
|
|
14
|
+
id: string;
|
|
15
|
+
username: string;
|
|
16
|
+
email?: string;
|
|
17
|
+
avatarUrl?: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface Me {
|
|
21
|
+
id: string;
|
|
22
|
+
username: string;
|
|
23
|
+
email?: string | null;
|
|
24
|
+
scoped?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface Pending {
|
|
27
|
+
sessionId: string;
|
|
28
|
+
sessionSecret: string;
|
|
29
|
+
expiresAt: number;
|
|
30
|
+
}
|
|
31
|
+
export type Resumed = {
|
|
32
|
+
kind: "none";
|
|
33
|
+
} | {
|
|
34
|
+
kind: "complete";
|
|
35
|
+
} | {
|
|
36
|
+
kind: "pending";
|
|
37
|
+
pending: Pending;
|
|
38
|
+
} | {
|
|
39
|
+
kind: "expired";
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The page that approves a CLI session. With a provider it signs a signed-out
|
|
43
|
+
* browser in with that method; without one it uses GitHub, as it always has.
|
|
44
|
+
*/
|
|
45
|
+
export declare function authUrlFor(sessionId: string, provider?: AuthProvider): string;
|
|
46
|
+
/** Which sign-in methods the platform offers. Both, if it cannot be asked. */
|
|
47
|
+
export declare function fetchAuthProviders(): Promise<AuthProvider[]>;
|
|
48
|
+
/** `--github` / `--google`, or undefined when neither is given. */
|
|
49
|
+
export declare function providerFlag(opts: {
|
|
50
|
+
github?: boolean;
|
|
51
|
+
google?: boolean;
|
|
52
|
+
}): AuthProvider | undefined;
|
|
53
|
+
/** Create a CLI login session on the server */
|
|
54
|
+
export declare function createSession(): Promise<SessionResponse>;
|
|
55
|
+
/** Check once if the user has completed authentication (no polling loop) */
|
|
56
|
+
export declare function checkSession(sessionId: string, sessionSecret: string): Promise<CheckResponse>;
|
|
57
|
+
/** The signed-in user, or null when this machine needs a sign-in. */
|
|
58
|
+
export declare function currentUser(): Promise<Me | null>;
|
|
59
|
+
/** Finish a session an earlier run left on disk, if the browser approved it. */
|
|
60
|
+
export declare function resumePending(): Promise<Resumed>;
|
|
61
|
+
export declare function startSession(provider?: AuthProvider): Promise<Pending>;
|
|
62
|
+
/**
|
|
63
|
+
* What an agent needs to get the user signed in: the links and what to do
|
|
64
|
+
* with them. `status` and `authUrl` are what `lizard login --json` has always
|
|
65
|
+
* printed; `authUrl` without a chosen method is the old link, which opens
|
|
66
|
+
* GitHub.
|
|
67
|
+
*/
|
|
68
|
+
export declare function pendingPayload(pending: Pending, methods: AuthProvider[], why: "new" | "waiting" | "expired", opts?: {
|
|
69
|
+
flag?: AuthProvider;
|
|
70
|
+
nextCommand?: string;
|
|
71
|
+
}, now?: number): {
|
|
72
|
+
instruction: string;
|
|
73
|
+
nextCommand?: string | undefined;
|
|
74
|
+
status: "pending";
|
|
75
|
+
authUrl: string;
|
|
76
|
+
authUrls: Partial<Record<AuthProvider, string>>;
|
|
77
|
+
expiresAt: string;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* The error a command fails with when nobody is signed in and nobody can be
|
|
81
|
+
* asked. Its body carries the sign-in links, so an agent can hand them to the
|
|
82
|
+
* user and run the command again, without a separate `lizard login`.
|
|
83
|
+
*/
|
|
84
|
+
export declare function loginRequiredError(resumed: Resumed, hadLogin: boolean): Promise<APIError>;
|
|
85
|
+
/**
|
|
86
|
+
* Sign in at a terminal: ask the method (when stdin can answer), open the
|
|
87
|
+
* browser there, wait for the approval, save the login. Throws if the link
|
|
88
|
+
* expires first.
|
|
89
|
+
*/
|
|
90
|
+
export declare function signInInteractive(flag?: AuthProvider): Promise<Me>;
|
|
91
|
+
export {};
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import * as p from "@clack/prompts";
|
|
3
|
+
import { api, APIError, clientHeaders, getBaseURL } from "./api.js";
|
|
4
|
+
import { clearCredentials, clearPendingAuth, envToken, loadPendingAuth, openURL, savePendingAuth, saveSessionLogin, validToken, } from "./auth.js";
|
|
5
|
+
export const AUTH_PROVIDERS = ["github", "google"];
|
|
6
|
+
const PROVIDER_LABEL = { github: "GitHub", google: "Google" };
|
|
7
|
+
/** How long the platform keeps a CLI session, for sessions saved without `expiresAt`. */
|
|
8
|
+
const SESSION_TTL_MS = 300_000;
|
|
9
|
+
/** The platform allows 60 polls per session over its 5 minutes: one every 5 s. */
|
|
10
|
+
const POLL_MS = 5_000;
|
|
11
|
+
/**
|
|
12
|
+
* The page that approves a CLI session. With a provider it signs a signed-out
|
|
13
|
+
* browser in with that method; without one it uses GitHub, as it always has.
|
|
14
|
+
*/
|
|
15
|
+
export function authUrlFor(sessionId, provider) {
|
|
16
|
+
const url = `${getBaseURL()}/auth/cli?session=${sessionId}`;
|
|
17
|
+
return provider ? `${url}&provider=${provider}` : url;
|
|
18
|
+
}
|
|
19
|
+
/** Which sign-in methods the platform offers. Both, if it cannot be asked. */
|
|
20
|
+
export async function fetchAuthProviders() {
|
|
21
|
+
try {
|
|
22
|
+
const res = await fetch(`${getBaseURL()}/api/auth/providers`, { headers: clientHeaders() });
|
|
23
|
+
if (!res.ok)
|
|
24
|
+
return AUTH_PROVIDERS;
|
|
25
|
+
const body = (await res.json());
|
|
26
|
+
const on = AUTH_PROVIDERS.filter((m) => body[m]);
|
|
27
|
+
return on.length ? on : AUTH_PROVIDERS;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return AUTH_PROVIDERS;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/** `--github` / `--google`, or undefined when neither is given. */
|
|
34
|
+
export function providerFlag(opts) {
|
|
35
|
+
if (opts.github && opts.google)
|
|
36
|
+
throw new Error("Pass --github or --google, not both.");
|
|
37
|
+
return opts.google ? "google" : opts.github ? "github" : undefined;
|
|
38
|
+
}
|
|
39
|
+
/** Create a CLI login session on the server */
|
|
40
|
+
export async function createSession() {
|
|
41
|
+
const res = await fetch(`${getBaseURL()}/api/auth/cli/session`, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: { ...clientHeaders(), "Content-Type": "application/json" },
|
|
44
|
+
});
|
|
45
|
+
if (!res.ok)
|
|
46
|
+
throw new Error(`Failed to create login session: ${res.statusText}`);
|
|
47
|
+
return res.json();
|
|
48
|
+
}
|
|
49
|
+
/** Check once if the user has completed authentication (no polling loop) */
|
|
50
|
+
export async function checkSession(sessionId, sessionSecret) {
|
|
51
|
+
const res = await fetch(`${getBaseURL()}/api/auth/cli/poll`, {
|
|
52
|
+
method: "POST",
|
|
53
|
+
// The platform records the login from this request; its User-Agent is
|
|
54
|
+
// what files it under the CLI and the agent running it.
|
|
55
|
+
headers: { ...clientHeaders(), "Content-Type": "application/json" },
|
|
56
|
+
body: JSON.stringify({ sessionId, sessionSecret }),
|
|
57
|
+
});
|
|
58
|
+
if (!res.ok)
|
|
59
|
+
throw new Error(`Auth check failed: ${res.statusText}`);
|
|
60
|
+
return res.json();
|
|
61
|
+
}
|
|
62
|
+
/** The signed-in user, or null when this machine needs a sign-in. */
|
|
63
|
+
export async function currentUser() {
|
|
64
|
+
if (!validToken())
|
|
65
|
+
return null;
|
|
66
|
+
try {
|
|
67
|
+
return await api.get("/api/auth/me");
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
// A saved token the platform no longer accepts is as good as none. A token
|
|
71
|
+
// from the environment is the caller's to fix, so that error stands.
|
|
72
|
+
if (err instanceof APIError && err.status === 401 && !envToken()) {
|
|
73
|
+
clearCredentials();
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
throw err;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** Finish a session an earlier run left on disk, if the browser approved it. */
|
|
80
|
+
export async function resumePending() {
|
|
81
|
+
const saved = loadPendingAuth();
|
|
82
|
+
if (!saved)
|
|
83
|
+
return { kind: "none" };
|
|
84
|
+
const pending = {
|
|
85
|
+
sessionId: saved.sessionId,
|
|
86
|
+
sessionSecret: saved.sessionSecret,
|
|
87
|
+
expiresAt: saved.expiresAt ?? saved.createdAt + SESSION_TTL_MS,
|
|
88
|
+
};
|
|
89
|
+
let result;
|
|
90
|
+
try {
|
|
91
|
+
result = await checkSession(pending.sessionId, pending.sessionSecret);
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
// A dropped request or the poll limit says nothing about the session.
|
|
95
|
+
if (Date.now() < pending.expiresAt)
|
|
96
|
+
return { kind: "pending", pending };
|
|
97
|
+
clearPendingAuth();
|
|
98
|
+
return { kind: "expired" };
|
|
99
|
+
}
|
|
100
|
+
if (result.status === "complete" && result.accessToken && result.user) {
|
|
101
|
+
saveSessionLogin({ accessToken: result.accessToken, user: result.user });
|
|
102
|
+
return { kind: "complete" };
|
|
103
|
+
}
|
|
104
|
+
if (result.status === "expired") {
|
|
105
|
+
clearPendingAuth();
|
|
106
|
+
return { kind: "expired" };
|
|
107
|
+
}
|
|
108
|
+
return { kind: "pending", pending };
|
|
109
|
+
}
|
|
110
|
+
export async function startSession(provider) {
|
|
111
|
+
const session = await createSession();
|
|
112
|
+
const now = Date.now();
|
|
113
|
+
const pending = {
|
|
114
|
+
sessionId: session.sessionId,
|
|
115
|
+
sessionSecret: session.sessionSecret,
|
|
116
|
+
expiresAt: now + session.expiresIn * 1000,
|
|
117
|
+
};
|
|
118
|
+
savePendingAuth({ ...pending, authUrl: authUrlFor(session.sessionId, provider), createdAt: now });
|
|
119
|
+
return pending;
|
|
120
|
+
}
|
|
121
|
+
/** Poll until the browser approves the session. Null if it expires first. */
|
|
122
|
+
async function waitForApproval(pending) {
|
|
123
|
+
while (Date.now() < pending.expiresAt) {
|
|
124
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_MS));
|
|
125
|
+
try {
|
|
126
|
+
const result = await checkSession(pending.sessionId, pending.sessionSecret);
|
|
127
|
+
if (result.status === "complete")
|
|
128
|
+
return result;
|
|
129
|
+
if (result.status === "expired")
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
// A dropped request or the poll limit: try again on the next tick.
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
// ── For agents ──────────────────────────────────────────────────────────
|
|
139
|
+
/**
|
|
140
|
+
* What an agent needs to get the user signed in: the links and what to do
|
|
141
|
+
* with them. `status` and `authUrl` are what `lizard login --json` has always
|
|
142
|
+
* printed; `authUrl` without a chosen method is the old link, which opens
|
|
143
|
+
* GitHub.
|
|
144
|
+
*/
|
|
145
|
+
export function pendingPayload(pending, methods, why, opts = {}, now = Date.now()) {
|
|
146
|
+
const authUrls = Object.fromEntries(methods.map((m) => [m, authUrlFor(pending.sessionId, m)]));
|
|
147
|
+
const single = methods.length === 1 ? methods[0] : undefined;
|
|
148
|
+
const minutes = Math.max(1, Math.round((pending.expiresAt - now) / 60_000));
|
|
149
|
+
const window = minutes === 1 ? "1 more minute" : `${minutes} more minutes`;
|
|
150
|
+
const then = opts.nextCommand ? "run nextCommand" : "run the same command again";
|
|
151
|
+
const lead = why === "waiting"
|
|
152
|
+
? "The user has not finished signing in yet. "
|
|
153
|
+
: why === "expired"
|
|
154
|
+
? "The last sign-in link expired; this is a new one. "
|
|
155
|
+
: "";
|
|
156
|
+
const instruction = single
|
|
157
|
+
? `${lead}Sign-in is needed. Give the user authUrl to open. Once the browser says "CLI authorized", ${then}. ` +
|
|
158
|
+
`The link works for ${window}; after that a new one is printed.`
|
|
159
|
+
: `${lead}Sign-in is needed. Ask the user how they sign in to Lizard and give them that link from authUrls. ` +
|
|
160
|
+
"Someone who already has an account must use the same method as before: another method opens a second, empty account " +
|
|
161
|
+
"unless both share a verified email. A new user can pick either. " +
|
|
162
|
+
`Once the browser says "CLI authorized", ${then}. The links work for ${window}; after that new ones are printed.`;
|
|
163
|
+
return {
|
|
164
|
+
status: "pending",
|
|
165
|
+
authUrl: single ? authUrls[single] : authUrlFor(pending.sessionId, opts.flag),
|
|
166
|
+
authUrls,
|
|
167
|
+
expiresAt: new Date(pending.expiresAt).toISOString(),
|
|
168
|
+
...(opts.nextCommand ? { nextCommand: opts.nextCommand } : {}),
|
|
169
|
+
instruction,
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The error a command fails with when nobody is signed in and nobody can be
|
|
174
|
+
* asked. Its body carries the sign-in links, so an agent can hand them to the
|
|
175
|
+
* user and run the command again, without a separate `lizard login`.
|
|
176
|
+
*/
|
|
177
|
+
export async function loginRequiredError(resumed, hadLogin) {
|
|
178
|
+
const base = hadLogin ? "The Lizard sign-in on this machine expired." : "Not signed in to Lizard.";
|
|
179
|
+
const plain = new APIError(401, `${base} Run \`lizard login\`, or set LIZARD_TOKEN (or LIZARD_API_KEY).`, "NOT_AUTHENTICATED");
|
|
180
|
+
// CI has nobody to open a link: say what to set and stop there.
|
|
181
|
+
if (process.env.CI)
|
|
182
|
+
return plain;
|
|
183
|
+
try {
|
|
184
|
+
const pending = resumed.kind === "pending" ? resumed.pending : await startSession();
|
|
185
|
+
const why = resumed.kind === "pending" ? "waiting" : resumed.kind === "expired" ? "expired" : "new";
|
|
186
|
+
const login = pendingPayload(pending, await fetchAuthProviders(), why);
|
|
187
|
+
return new APIError(401, `${base} ${login.instruction}`, "NOT_AUTHENTICATED", { login });
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
return plain;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
// ── For people ──────────────────────────────────────────────────────────
|
|
194
|
+
function cancelled() {
|
|
195
|
+
p.cancel("Cancelled.");
|
|
196
|
+
process.exit(5);
|
|
197
|
+
}
|
|
198
|
+
async function askProvider() {
|
|
199
|
+
const methods = await fetchAuthProviders();
|
|
200
|
+
if (methods.length === 1)
|
|
201
|
+
return methods[0];
|
|
202
|
+
p.log.message(chalk.dim("Already have an account? Pick the method you signed up with."));
|
|
203
|
+
const choice = await p.select({
|
|
204
|
+
message: "How do you sign in to Lizard?",
|
|
205
|
+
options: methods.map((m) => ({ value: m, label: PROVIDER_LABEL[m] })),
|
|
206
|
+
});
|
|
207
|
+
if (p.isCancel(choice))
|
|
208
|
+
cancelled();
|
|
209
|
+
return choice;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Sign in at a terminal: ask the method (when stdin can answer), open the
|
|
213
|
+
* browser there, wait for the approval, save the login. Throws if the link
|
|
214
|
+
* expires first.
|
|
215
|
+
*/
|
|
216
|
+
export async function signInInteractive(flag) {
|
|
217
|
+
const provider = flag ?? (process.stdin.isTTY ? await askProvider() : undefined);
|
|
218
|
+
const pending = await startSession(provider);
|
|
219
|
+
if (provider) {
|
|
220
|
+
const url = authUrlFor(pending.sessionId, provider);
|
|
221
|
+
const opened = await openURL(url);
|
|
222
|
+
p.log.info(`${opened ? "Opened your browser. If it did not open, use this link" : "Open this link to sign in"}:\n${chalk.cyan(url)}`);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
const methods = await fetchAuthProviders();
|
|
226
|
+
p.log.info(["Open one of these links to sign in:", ...methods.map((m) => `${PROVIDER_LABEL[m]}: ${chalk.cyan(authUrlFor(pending.sessionId, m))}`)].join("\n"));
|
|
227
|
+
}
|
|
228
|
+
// Ctrl+C at a terminal never reaches onCancel: clack holds stdin raw while it
|
|
229
|
+
// spins and exits on the keypress itself, printing cancelMessage on the way
|
|
230
|
+
// out. So the message carries the hint, and the session stays on disk for
|
|
231
|
+
// whichever lizard command runs next.
|
|
232
|
+
const spin = p.spinner({
|
|
233
|
+
cancelMessage: "Stopped waiting. The link works for a few more minutes: finish in the browser, then run the command again",
|
|
234
|
+
onCancel: () => process.exit(5),
|
|
235
|
+
});
|
|
236
|
+
spin.start("Waiting for you to authorize Lizard CLI in the browser");
|
|
237
|
+
const result = await waitForApproval(pending);
|
|
238
|
+
if (!result?.accessToken || !result.user) {
|
|
239
|
+
spin.error("The sign-in link expired");
|
|
240
|
+
clearPendingAuth();
|
|
241
|
+
throw new Error("The sign-in link expired. Run the command again for a new one.");
|
|
242
|
+
}
|
|
243
|
+
saveSessionLogin({ accessToken: result.accessToken, user: result.user });
|
|
244
|
+
spin.stop("Authorized");
|
|
245
|
+
const me = await api.get("/api/auth/me");
|
|
246
|
+
p.log.success(`Signed in as ${chalk.bold(me.username)}`);
|
|
247
|
+
return me;
|
|
248
|
+
}
|
|
249
|
+
//# sourceMappingURL=signin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signin.js","sourceRoot":"","sources":["../../src/lib/signin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,CAAC,MAAM,gBAAgB,CAAC;AACpC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,eAAe,EACf,OAAO,EACP,eAAe,EACf,gBAAgB,EAChB,UAAU,GACX,MAAM,WAAW,CAAC;AAanB,MAAM,CAAC,MAAM,cAAc,GAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AACnE,MAAM,cAAc,GAAiC,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAE5F,yFAAyF;AACzF,MAAM,cAAc,GAAG,OAAO,CAAC;AAC/B,kFAAkF;AAClF,MAAM,OAAO,GAAG,KAAK,CAAC;AAsCtB;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,SAAiB,EAAE,QAAuB;IACnE,MAAM,GAAG,GAAG,GAAG,UAAU,EAAE,qBAAqB,SAAS,EAAE,CAAC;IAC5D,OAAO,QAAQ,CAAC,CAAC,CAAC,GAAG,GAAG,aAAa,QAAQ,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;AACxD,CAAC;AAED,8EAA8E;AAC9E,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,UAAU,EAAE,qBAAqB,EAAE,EAAE,OAAO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