|
1 | 1 | import * as vscode from "vscode" |
2 | | -import os from "os" |
3 | 2 |
|
4 | 3 | import { Package } from "../shared/package" |
5 | 4 |
|
@@ -200,25 +199,33 @@ export function getZooCodeBaseUrl(): string { |
200 | 199 | return config.get<string>("baseUrl") || process.env.ZOO_CODE_BASE_URL || "https://www.zoocode.dev" |
201 | 200 | } |
202 | 201 |
|
203 | | -export async function startZooCodeAuth(): Promise<void> { |
204 | | - const baseUrl = getZooCodeBaseUrl() |
205 | | - const deviceName = os.hostname() |
206 | | - const editor = "VS Code" |
207 | | - const version = Package.version |
208 | | - |
209 | | - const callbackUri = await vscode.env.asExternalUri(vscode.Uri.parse("vscode://zoo-code.zoo-code/auth-callback")) |
210 | | - |
211 | | - const authUrl = `${baseUrl}/dashboard/connect?device=${encodeURIComponent(deviceName)}&editor=${encodeURIComponent(editor)}&version=${encodeURIComponent(version)}&callback_uri=${encodeURIComponent(callbackUri.toString())}` |
212 | | - |
213 | | - await vscode.env.openExternal(vscode.Uri.parse(authUrl)) |
214 | | -} |
215 | | - |
216 | 202 | export async function handleAuthCallback(token: string): Promise<boolean> { |
217 | 203 | if (!token || !token.startsWith("zoo_ext_")) { |
218 | 204 | vscode.window.showErrorMessage("Zoo Code: Invalid authentication token received.") |
219 | 205 | return false |
220 | 206 | } |
221 | 207 |
|
| 208 | + // Verify token with backend before storing |
| 209 | + const baseUrl = getZooCodeBaseUrl() |
| 210 | + try { |
| 211 | + const response = await fetch(`${baseUrl}/api/extension/auth/verify`, { |
| 212 | + headers: { Authorization: `Bearer ${token}` }, |
| 213 | + signal: AbortSignal.timeout(10_000), |
| 214 | + }) |
| 215 | + if (!response.ok) { |
| 216 | + vscode.window.showErrorMessage("Zoo Code: Token verification failed.") |
| 217 | + return false |
| 218 | + } |
| 219 | + const data = (await response.json()) as { valid?: boolean } |
| 220 | + if (!data.valid) { |
| 221 | + vscode.window.showErrorMessage("Zoo Code: Invalid token.") |
| 222 | + return false |
| 223 | + } |
| 224 | + } catch { |
| 225 | + vscode.window.showErrorMessage("Zoo Code: Could not verify token.") |
| 226 | + return false |
| 227 | + } |
| 228 | + |
222 | 229 | await setZooCodeToken(token) |
223 | 230 |
|
224 | 231 | // Check subscription status after successful auth |
|
0 commit comments