-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix authentication in Firebase Studio IDE #6371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -242,6 +242,24 @@ export class WebAuthService extends EventEmitter<AuthServiceEvents> implements A | |
| * This method initiates the authentication flow by generating a state parameter | ||
| * and opening the browser to the authorization URL. | ||
| */ | ||
| /** | ||
| * Detects if running in Firebase Studio IDE (formerly IDX Google) environment | ||
| */ | ||
| private isFirebaseStudioIDE(): boolean { | ||
| const appName = vscode.env.appName?.toLowerCase() || "" | ||
| const remoteName = vscode.env.remoteName?.toLowerCase() || "" | ||
|
|
||
| return ( | ||
| appName.includes("idx") || | ||
| appName.includes("firebase") || | ||
| appName.includes("studio") || | ||
| remoteName.includes("idx") || | ||
| remoteName.includes("firebase") || | ||
| process.env.IDX_WORKSPACE_ID !== undefined || | ||
| process.env.FIREBASE_PROJECT_ID !== undefined | ||
| ) | ||
| } | ||
|
|
||
| public async login(): Promise<void> { | ||
| try { | ||
| // Generate a cryptographically random state parameter. | ||
|
|
@@ -250,11 +268,34 @@ export class WebAuthService extends EventEmitter<AuthServiceEvents> implements A | |
| const packageJSON = this.context.extension?.packageJSON | ||
| const publisher = packageJSON?.publisher ?? "RooVeterinaryInc" | ||
| const name = packageJSON?.name ?? "roo-cline" | ||
|
|
||
| const isCloudIDE = this.isFirebaseStudioIDE() | ||
| this.log(`[auth] Initiating login - Firebase Studio IDE detected: ${isCloudIDE}`) | ||
| this.log(`[auth] App name: ${vscode.env.appName}`) | ||
| this.log(`[auth] Remote name: ${vscode.env.remoteName}`) | ||
| this.log(`[auth] URI scheme: ${vscode.env.uriScheme}`) | ||
|
|
||
| const params = new URLSearchParams({ | ||
| state, | ||
| auth_redirect: `${vscode.env.uriScheme}://${publisher}.${name}`, | ||
| }) | ||
|
|
||
| // Add cloud IDE indicator for server-side handling | ||
| if (isCloudIDE) { | ||
| params.append("cloud_ide", "firebase_studio") | ||
| } | ||
|
|
||
| const url = `${getRooCodeApiUrl()}/extension/sign-in?${params.toString()}` | ||
| this.log(`[auth] Opening authentication URL: ${url}`) | ||
|
|
||
| if (isCloudIDE) { | ||
| // Show additional guidance for Firebase Studio IDE users | ||
| vscode.window.showInformationMessage( | ||
| "Opening authentication in Firebase Studio IDE. After signing in, the callback should be automatically handled.", | ||
| { modal: false }, | ||
| ) | ||
| } | ||
|
|
||
| await vscode.env.openExternal(vscode.Uri.parse(url)) | ||
| } catch (error) { | ||
| this.log(`[auth] Error initiating Roo Code Cloud auth: ${error}`) | ||
|
|
@@ -277,8 +318,24 @@ export class WebAuthService extends EventEmitter<AuthServiceEvents> implements A | |
| state: string | null, | ||
| organizationId?: string | null, | ||
| ): Promise<void> { | ||
| const isCloudIDE = this.isFirebaseStudioIDE() | ||
|
|
||
| this.log(`[auth] Handling callback - Firebase Studio IDE: ${isCloudIDE}`) | ||
| this.log(`[auth] Code present: ${!!code}, State present: ${!!state}`) | ||
|
|
||
| if (!code || !state) { | ||
| vscode.window.showInformationMessage("Invalid Roo Code Cloud sign in url") | ||
| const message = "Invalid Roo Code Cloud sign in url" | ||
| this.log(`[auth] ${message}`) | ||
|
|
||
| if (isCloudIDE) { | ||
| // Provide more specific guidance for Firebase Studio IDE | ||
| vscode.window.showErrorMessage( | ||
| "Authentication callback failed in Firebase Studio IDE. Please try signing in again. " + | ||
| "If the issue persists, check that popup blockers are disabled and the extension has proper permissions.", | ||
| ) | ||
| } else { | ||
| vscode.window.showInformationMessage(message) | ||
| } | ||
| return | ||
| } | ||
|
|
||
|
|
@@ -288,20 +345,40 @@ export class WebAuthService extends EventEmitter<AuthServiceEvents> implements A | |
|
|
||
| if (state !== storedState) { | ||
| this.log("[auth] State mismatch in callback") | ||
| this.log(`[auth] Expected state: ${storedState}, Received state: ${state}`) | ||
| throw new Error("Invalid state parameter. Authentication request may have been tampered with.") | ||
| } | ||
|
|
||
| this.log("[auth] State validation successful, proceeding with sign-in") | ||
| const credentials = await this.clerkSignIn(code) | ||
|
|
||
| // Set organizationId (null for personal accounts) | ||
| credentials.organizationId = organizationId || null | ||
|
|
||
| await this.storeCredentials(credentials) | ||
|
|
||
| vscode.window.showInformationMessage("Successfully authenticated with Roo Code Cloud") | ||
| const successMessage = "Successfully authenticated with Roo Code Cloud" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency with naming guidelines, consider using 'Roo Code' instead of 'Roo Code Cloud' when referring to the product in user-facing messages. This comment was generated because it violated a code review rule: irule_VrRKWqywZ2YV2SOE. |
||
| if (isCloudIDE) { | ||
| vscode.window.showInformationMessage( | ||
| `${successMessage} in Firebase Studio IDE. You can now use Roo Code Cloud features.`, | ||
| ) | ||
| } else { | ||
| vscode.window.showInformationMessage(successMessage) | ||
| } | ||
|
|
||
| this.log("[auth] Successfully authenticated with Roo Code Cloud") | ||
| } catch (error) { | ||
| this.log(`[auth] Error handling Roo Code Cloud callback: ${error}`) | ||
|
|
||
| if (isCloudIDE) { | ||
| // Provide more detailed error information for Firebase Studio IDE | ||
| const errorMessage = error instanceof Error ? error.message : String(error) | ||
| vscode.window.showErrorMessage( | ||
| `Authentication failed in Firebase Studio IDE: ${errorMessage}. ` + | ||
| "Please try again or contact support if the issue persists.", | ||
| ) | ||
| } | ||
|
|
||
| const previousState = this.state | ||
| this.state = "logged-out" | ||
| this.emit("logged-out", { previousState }) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,46 @@ | ||
| import * as vscode from "vscode" | ||
|
|
||
| /** | ||
| * Detects if running in Firebase Studio IDE (formerly IDX Google) environment | ||
| */ | ||
| function isFirebaseStudioIDE(): boolean { | ||
| const appName = vscode.env.appName?.toLowerCase() || "" | ||
| const remoteName = vscode.env.remoteName?.toLowerCase() || "" | ||
|
|
||
| return ( | ||
| appName.includes("idx") || | ||
| appName.includes("firebase") || | ||
| appName.includes("studio") || | ||
| remoteName.includes("idx") || | ||
| remoteName.includes("firebase") || | ||
| process.env.IDX_WORKSPACE_ID !== undefined || | ||
| process.env.FIREBASE_PROJECT_ID !== undefined | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Get the User-Agent string for API requests | ||
| * @param context Optional extension context for more accurate version detection | ||
| * @returns User-Agent string in format "Roo-Code {version}" | ||
| * @returns User-Agent string in format "Roo-Code {version} ({environment})" | ||
| */ | ||
| export function getUserAgent(context?: vscode.ExtensionContext): string { | ||
| return `Roo-Code ${context?.extension?.packageJSON?.version || "unknown"}` | ||
| const version = context?.extension?.packageJSON?.version || "unknown" | ||
| const baseUserAgent = `Roo-Code ${version}` | ||
|
|
||
| // Add environment information for better debugging | ||
| const environment = [] | ||
|
|
||
| if (isFirebaseStudioIDE()) { | ||
| environment.push("Firebase-Studio-IDE") | ||
| } | ||
|
|
||
| if (vscode.env.remoteName) { | ||
| environment.push(`Remote-${vscode.env.remoteName}`) | ||
| } | ||
|
|
||
| if (environment.length > 0) { | ||
| return `${baseUserAgent} (${environment.join("; ")})` | ||
| } | ||
|
|
||
| return baseUserAgent | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Userβfacing messages (e.g. the authentication guidance) are hardcoded. Use the translation (i18n) function instead to support localization.
This comment was generated because it violated a code review rule: irule_C0ez7Rji6ANcGkkX.