Add getCallUri to the HostProvider (#5322)
**Centralize callback URI management** through the HostProvider instead of having it in multiple places in the codebase. **Simplify error handling** by making the callback URI required rather than optional The changes are related to **authentication callback URI handling** in the Cline extension. Here's what's being modified: - Simplified callback URI retrieval - Changed return type from `Promise<string | undefined>` to `Promise<string>` - Now throws an error if AuthHandler is not enabled instead of returning undefined - Added a new `getCallbackUri` property that returns a `Promise<string>` - This allows the host provider to supply callback URIs for authentication - Implemented callback URI provider - Updated to use HostProvider for callback URI - Updated to match new signature
This commit is contained in:
1 parent
8fee09f09e
commit
b8227c19c3
7 files changed
+39
-30
No files matched your search
@@ -61,6 +61,7 @@ describe("FileContextTracker", () => {
|
||||
(() => {}) as DiffViewProviderCreator,
|
||||
vscodeHostBridgeClient,
|
||||
(_) => {},
|
||||
async () => "",
|
||||
)
|
||||
|
||||
// Create tracker instance
|
||||
|
||||
+4
-1
@@ -663,7 +663,10 @@ function maybeSetupHostProviders(context: ExtensionContext) {
|
||||
const outputChannel = vscode.window.createOutputChannel("Cline")
|
||||
context.subscriptions.push(outputChannel)
|
||||
|
||||
HostProvider.initialize(createWebview, createDiffView, vscodeHostBridgeClient, outputChannel.appendLine)
|
||||
const getCallbackUri = async function () {
|
||||
return `${vscode.env.uriScheme || "vscode"}://saoudrizwan.claude-dev`
|
||||
}
|
||||
HostProvider.initialize(createWebview, createDiffView, vscodeHostBridgeClient, outputChannel.appendLine, getCallbackUri)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+18
-24
@@ -1,7 +1,6 @@
|
||||
import type { IncomingMessage, Server, ServerResponse } from "node:http"
|
||||
import http from "node:http"
|
||||
import type { AddressInfo } from "node:net"
|
||||
import { clineEnvConfig } from "@/config"
|
||||
import { openExternal } from "@/utils/env"
|
||||
import { SharedUriHandler } from "@/services/uri/SharedUriHandler"
|
||||
|
||||
@@ -36,30 +35,25 @@ export class AuthHandler {
|
||||
this.enabled = enabled
|
||||
}
|
||||
|
||||
public async getCallbackUri(): Promise<string | undefined> {
|
||||
try {
|
||||
if (!this.enabled) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
if (!this.server) {
|
||||
// If server creation is already in progress, wait for it
|
||||
if (this.serverCreationPromise) {
|
||||
await this.serverCreationPromise
|
||||
} else {
|
||||
// Start server creation and track the promise
|
||||
this.serverCreationPromise = this.createServer()
|
||||
await this.serverCreationPromise
|
||||
}
|
||||
} else {
|
||||
this.updateTimeout()
|
||||
}
|
||||
|
||||
return `http://127.0.0.1:${this.port}`
|
||||
} catch (error) {
|
||||
console.error("AuthHandler.getCallbackUri error:", error)
|
||||
return undefined
|
||||
public async getCallbackUri(): Promise<string> {
|
||||
if (!this.enabled) {
|
||||
throw Error("AuthHandler was not enabled")
|
||||
}
|
||||
|
||||
if (!this.server) {
|
||||
// If server creation is already in progress, wait for it
|
||||
if (this.serverCreationPromise) {
|
||||
await this.serverCreationPromise
|
||||
} else {
|
||||
// Start server creation and track the promise
|
||||
this.serverCreationPromise = this.createServer()
|
||||
await this.serverCreationPromise
|
||||
}
|
||||
} else {
|
||||
this.updateTimeout()
|
||||
}
|
||||
|
||||
return `http://127.0.0.1:${this.port}`
|
||||
}
|
||||
|
||||
private async createServer(): Promise<void> {
|
||||
|
||||
@@ -26,17 +26,22 @@ export class HostProvider {
|
||||
// Logs to a user-visible output channel.
|
||||
logToChannel: LogToChannel
|
||||
|
||||
// Returns a callback URI that will redirect to Cline.
|
||||
getCallbackUri: () => Promise<string>
|
||||
|
||||
// Private constructor to enforce singleton pattern
|
||||
private constructor(
|
||||
createWebviewProvider: WebviewProviderCreator,
|
||||
createDiffViewProvider: DiffViewProviderCreator,
|
||||
hostBridge: HostBridgeClientProvider,
|
||||
logToChannel: LogToChannel,
|
||||
getCallbackUri: () => Promise<string>,
|
||||
) {
|
||||
this.createWebviewProvider = createWebviewProvider
|
||||
this.createDiffViewProvider = createDiffViewProvider
|
||||
this.hostBridge = hostBridge
|
||||
this.logToChannel = logToChannel
|
||||
this.getCallbackUri = getCallbackUri
|
||||
}
|
||||
|
||||
public static initialize(
|
||||
@@ -44,6 +49,7 @@ export class HostProvider {
|
||||
diffViewProviderCreator: DiffViewProviderCreator,
|
||||
hostBridgeProvider: HostBridgeClientProvider,
|
||||
logToChannel: LogToChannel,
|
||||
getCallbackUri: () => Promise<string>,
|
||||
): HostProvider {
|
||||
if (HostProvider.instance) {
|
||||
throw new Error("Host providers have already been initialized.")
|
||||
@@ -53,6 +59,7 @@ export class HostProvider {
|
||||
diffViewProviderCreator,
|
||||
hostBridgeProvider,
|
||||
logToChannel,
|
||||
getCallbackUri,
|
||||
)
|
||||
return HostProvider.instance
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import { type EmptyRequest, String } from "@shared/proto/cline/common"
|
||||
import { AuthHandler } from "@/hosts/external/AuthHandler"
|
||||
import { FirebaseAuthProvider } from "./providers/FirebaseAuthProvider"
|
||||
import { openExternal } from "@/utils/env"
|
||||
import { HostProvider } from "@/hosts/host-provider"
|
||||
|
||||
const DefaultClineAccountURI = `${clineEnvConfig.appBaseUrl}/auth`
|
||||
let authProviders: any[] = []
|
||||
@@ -196,8 +197,7 @@ export class AuthService {
|
||||
throw new Error("Authentication URI is not configured")
|
||||
}
|
||||
|
||||
const callbackHost =
|
||||
(await AuthHandler.getInstance().getCallbackUri()) || `${vscode.env.uriScheme || "vscode"}://saoudrizwan.claude-dev`
|
||||
const callbackHost = await HostProvider.get().getCallbackUri()
|
||||
const callbackUrl = `${callbackHost}/auth`
|
||||
|
||||
// Use URL object for more graceful query construction
|
||||
|
||||
@@ -17,6 +17,8 @@ import { DiffViewProvider } from "@/integrations/editor/DiffViewProvider"
|
||||
async function main() {
|
||||
log("\n\n\nStarting cline-core service...\n\n\n")
|
||||
|
||||
AuthHandler.getInstance().setEnabled(true)
|
||||
|
||||
setupHostProvider()
|
||||
|
||||
// Set up global error handlers to prevent process crashes
|
||||
@@ -28,8 +30,6 @@ async function main() {
|
||||
// Create controller with cache service
|
||||
const controller = new Controller(extensionContext, postMessage, uuidv4())
|
||||
startProtobusService(controller)
|
||||
|
||||
AuthHandler.getInstance().setEnabled(true)
|
||||
}
|
||||
|
||||
function setupHostProvider() {
|
||||
@@ -39,8 +39,11 @@ function setupHostProvider() {
|
||||
const createDiffView = (): DiffViewProvider => {
|
||||
return new ExternalDiffViewProvider()
|
||||
}
|
||||
const getCallbackUri = (): Promise<string> => {
|
||||
return AuthHandler.getInstance().getCallbackUri()
|
||||
}
|
||||
|
||||
HostProvider.initialize(createWebview, createDiffView, new ExternalHostBridgeClientManager(), log)
|
||||
HostProvider.initialize(createWebview, createDiffView, new ExternalHostBridgeClientManager(), log, getCallbackUri)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,6 +25,7 @@ describe("ClineAPI Core Functionality", () => {
|
||||
(() => {}) as DiffViewProviderCreator,
|
||||
vscodeHostBridgeClient,
|
||||
mockLogToChannel,
|
||||
async () => "",
|
||||
)
|
||||
// Stub the getGlobalState function from the state module
|
||||
// This is needed because the real createClineAPI uses it for getCustomInstructions
|
||||
|
||||
Reference in new issue
Block a user