From 4b0db7a561fc43ef0c71d2be823c15350ae643a6 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Thu, 4 Sep 2025 18:23:12 +0000 Subject: [PATCH] fix(auth): use vscode.env.asExternalUri for auth_redirect to target Codespaces/web --- packages/cloud/src/WebAuthService.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/cloud/src/WebAuthService.ts b/packages/cloud/src/WebAuthService.ts index 934ca90b71..bb010dcadb 100644 --- a/packages/cloud/src/WebAuthService.ts +++ b/packages/cloud/src/WebAuthService.ts @@ -260,13 +260,30 @@ export class WebAuthService extends EventEmitter implements A // Generate a cryptographically random state parameter. const state = crypto.randomBytes(16).toString("hex") await this.context.globalState.update(AUTH_STATE_KEY, state) + + // Resolve the deep link target for the CURRENT VS Code instance. + // In remote/web (e.g. GitHub Codespaces), asExternalUri produces an HTTPS URL + // that routes back to the running instance instead of launching a local VS Code. const packageJSON = this.context.extension?.packageJSON const publisher = packageJSON?.publisher ?? "RooVeterinaryInc" const name = packageJSON?.name ?? "roo-cline" + + const deepLink = vscode.Uri.parse(`${vscode.env.uriScheme}://${publisher}.${name}`) + + let authRedirect = deepLink.toString() + try { + const external = await vscode.env.asExternalUri(deepLink) + authRedirect = external.toString() + } catch (e) { + // Fallback to the raw deep link if resolution fails (desktop will still work). + this.log(`[auth] asExternalUri failed, falling back to deep link: ${e}`) + } + const params = new URLSearchParams({ state, - auth_redirect: `${vscode.env.uriScheme}://${publisher}.${name}`, + auth_redirect: authRedirect, }) + const url = `${getRooCodeApiUrl()}/extension/sign-in?${params.toString()}` await vscode.env.openExternal(vscode.Uri.parse(url)) } catch (error) {