Skip to content

Commit 7a65fb8

Browse files
lishengzxcclaude
andcommitted
feat(auth): parse and persist workspace_id from console login callback
Adapts to bailian-cli-login af06baf which added workspace_id to the notifyToken payload. The field is parsed from query/body and written to config.json as workspace_id. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f45b19c commit 7a65fb8

1 file changed

Lines changed: 19 additions & 4 deletions

File tree

packages/cli/src/commands/auth/login-console.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function parseApiKeyFromRawBody(raw: string, contentType: string): string | null
215215

216216
type CallbackExtras = Pick<
217217
CallbackCredentials,
218-
"baseUrl" | "consoleSite" | "consoleRegion" | "consoleSwitchAgent"
218+
"baseUrl" | "consoleSite" | "consoleRegion" | "consoleSwitchAgent" | "workspaceId"
219219
>;
220220

221221
function stringField(o: Record<string, unknown>, ...keys: string[]): string | null {
@@ -232,6 +232,7 @@ function parseExtrasFromRawBody(raw: string, contentType: string): CallbackExtra
232232
consoleSite: null,
233233
consoleRegion: null,
234234
consoleSwitchAgent: null,
235+
workspaceId: null,
235236
};
236237
if (!raw.trim()) return empty;
237238

@@ -270,6 +271,7 @@ function parseExtrasFromRawBody(raw: string, contentType: string): CallbackExtra
270271
consoleSite: stringField(obj, "console_site", "consoleSite"),
271272
consoleRegion: stringField(obj, "console_region", "consoleRegion"),
272273
consoleSwitchAgent: stringField(obj, "console_switch_agent", "consoleSwitchAgent"),
274+
workspaceId: stringField(obj, "workspace_id", "workspaceId"),
273275
};
274276
}
275277

@@ -280,6 +282,7 @@ interface CallbackCredentials {
280282
consoleSite: string | null;
281283
consoleRegion: string | null;
282284
consoleSwitchAgent: string | null;
285+
workspaceId: string | null;
283286
}
284287

285288
async function extractCredentialsFromRequest(
@@ -296,12 +299,15 @@ async function extractCredentialsFromRequest(
296299
u.searchParams.get("console_region") ?? u.searchParams.get("consoleRegion");
297300
const consoleSwitchAgentFromQuery =
298301
u.searchParams.get("console_switch_agent") ?? u.searchParams.get("consoleSwitchAgent");
302+
const workspaceIdFromQuery =
303+
u.searchParams.get("workspace_id") ?? u.searchParams.get("workspaceId");
299304

300305
const extras = {
301306
baseUrl: baseUrlFromQuery?.trim() || null,
302307
consoleSite: consoleSiteFromQuery?.trim() || null,
303308
consoleRegion: consoleRegionFromQuery?.trim() || null,
304309
consoleSwitchAgent: consoleSwitchAgentFromQuery?.trim() || null,
310+
workspaceId: workspaceIdFromQuery?.trim() || null,
305311
};
306312

307313
const m = req.method ?? "GET";
@@ -337,6 +343,7 @@ async function extractCredentialsFromRequest(
337343
consoleSite: extras.consoleSite || bodyExtras.consoleSite,
338344
consoleRegion: extras.consoleRegion || bodyExtras.consoleRegion,
339345
consoleSwitchAgent: extras.consoleSwitchAgent || bodyExtras.consoleSwitchAgent,
346+
workspaceId: extras.workspaceId || bodyExtras.workspaceId,
340347
};
341348
}
342349

@@ -454,11 +461,18 @@ export async function runConsoleLogin(
454461
return;
455462
}
456463

457-
const { accessToken, apiKey, baseUrl, consoleSite, consoleRegion, consoleSwitchAgent } =
458-
await extractCredentialsFromRequest(req);
464+
const {
465+
accessToken,
466+
apiKey,
467+
baseUrl,
468+
consoleSite,
469+
consoleRegion,
470+
consoleSwitchAgent,
471+
workspaceId,
472+
} = await extractCredentialsFromRequest(req);
459473

460474
const hasConfig =
461-
accessToken || baseUrl || consoleSite || consoleRegion || consoleSwitchAgent;
475+
accessToken || baseUrl || consoleSite || consoleRegion || consoleSwitchAgent || workspaceId;
462476

463477
if (hasConfig || apiKey) {
464478
try {
@@ -469,6 +483,7 @@ export async function runConsoleLogin(
469483
if (consoleSite) existing.console_site = consoleSite;
470484
if (consoleRegion) existing.console_region = consoleRegion;
471485
if (consoleSwitchAgent) existing.console_switch_agent = Number(consoleSwitchAgent);
486+
if (workspaceId) existing.workspace_id = workspaceId;
472487
await writeConfigFile(existing);
473488
process.stderr.write(`Config saved to ${getConfigPath()}\n`);
474489
}

0 commit comments

Comments
 (0)