@storyclaw/talenthub 0.3.4 → 0.3.5
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/dist/commands/login.js +16 -7
- package/dist/lib/auth.d.ts +6 -0
- package/dist/lib/auth.js +15 -0
- package/package.json +1 -1
package/dist/commands/login.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execSync } from "node:child_process";
|
|
2
|
-
import { readAuth, requestDeviceCode, pollForToken, exchangeToken, writeAuth } from "../lib/auth.js";
|
|
2
|
+
import { readAuth, requestDeviceCode, pollForToken, exchangeToken, verifyToken, writeAuth } from "../lib/auth.js";
|
|
3
3
|
function openUrl(url) {
|
|
4
4
|
try {
|
|
5
5
|
const cmd = process.platform === "darwin"
|
|
@@ -14,14 +14,23 @@ function openUrl(url) {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
export async function login(options) {
|
|
17
|
-
// Direct token exchange: skip device-code flow entirely
|
|
18
17
|
if (options.token) {
|
|
19
|
-
console.log("Exchanging token...");
|
|
20
18
|
try {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
if (options.token.startsWith("th_")) {
|
|
20
|
+
console.log("Verifying token...");
|
|
21
|
+
const { user_id } = await verifyToken(options.token);
|
|
22
|
+
writeAuth({ token: options.token, user_id, expires_at: "" });
|
|
23
|
+
console.log(`✓ Logged in successfully.`);
|
|
24
|
+
console.log(` User ID: ${user_id}`);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// sc_token from web session — exchange for a CLI token
|
|
28
|
+
console.log("Exchanging token...");
|
|
29
|
+
const { access_token, user_id, expires_at } = await exchangeToken(options.token);
|
|
30
|
+
writeAuth({ token: access_token, user_id, expires_at });
|
|
31
|
+
console.log(`✓ Logged in successfully.`);
|
|
32
|
+
console.log(` User ID: ${user_id}`);
|
|
33
|
+
}
|
|
25
34
|
}
|
|
26
35
|
catch (err) {
|
|
27
36
|
console.error(`✗ Login failed: ${err instanceof Error ? err.message : err}`);
|
package/dist/lib/auth.d.ts
CHANGED
|
@@ -24,4 +24,10 @@ export type TokenResponse = {
|
|
|
24
24
|
* Exchange an sc_token (web session cookie) for a CLI-compatible th_* token.
|
|
25
25
|
*/
|
|
26
26
|
export declare function exchangeToken(scToken: string): Promise<TokenResponse>;
|
|
27
|
+
/**
|
|
28
|
+
* Verify a th_* CLI token against the registry and return the user_id.
|
|
29
|
+
*/
|
|
30
|
+
export declare function verifyToken(token: string): Promise<{
|
|
31
|
+
user_id: string;
|
|
32
|
+
}>;
|
|
27
33
|
export declare function pollForToken(deviceCode: string, interval: number, maxWaitMs: number): Promise<TokenResponse>;
|
package/dist/lib/auth.js
CHANGED
|
@@ -64,6 +64,21 @@ export async function exchangeToken(scToken) {
|
|
|
64
64
|
}
|
|
65
65
|
return res.json();
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Verify a th_* CLI token against the registry and return the user_id.
|
|
69
|
+
*/
|
|
70
|
+
export async function verifyToken(token) {
|
|
71
|
+
const base = getRegistryBaseUrl();
|
|
72
|
+
const res = await fetchRetry(`${base}/api/talenthub/auth/me`, {
|
|
73
|
+
method: "GET",
|
|
74
|
+
headers: { Authorization: `Bearer ${token}` },
|
|
75
|
+
});
|
|
76
|
+
if (!res.ok) {
|
|
77
|
+
const body = await res.json().catch(() => ({ error: "unknown" }));
|
|
78
|
+
throw new Error(`Token verification failed (${res.status}): ${body.error ?? "unknown error"}`);
|
|
79
|
+
}
|
|
80
|
+
return res.json();
|
|
81
|
+
}
|
|
67
82
|
export async function pollForToken(deviceCode, interval, maxWaitMs) {
|
|
68
83
|
const base = getRegistryBaseUrl();
|
|
69
84
|
const deadline = Date.now() + maxWaitMs;
|