feat: add pkce

This commit is contained in:
Frank
2025-01-15 08:20:20 +11:00
parent 6b15f827d8
commit a102ba520b
3 changed files with 47 additions and 5 deletions

View File

@@ -1273,6 +1273,33 @@ export class ClineProvider implements vscode.WebviewViewProvider {
return cacheDir
}
async handleGlamaCallback(code: string) {
let apiKey: string
try {
const response = await axios.post("https://glama.ai/api/gateway/v1/auth/exchange-code", { code })
if (response.data && response.data.apiKey) {
apiKey = response.data.apiKey
} else {
throw new Error("Invalid response from Glama API")
}
} catch (error) {
console.error("Error exchanging code for API key:", error)
throw error
}
const glama: ApiProvider = "glama"
await this.updateGlobalState("apiProvider", glama)
await this.storeSecret("glamaApiKey", apiKey)
await this.postStateToWebview()
if (this.cline) {
this.cline.api = buildApiHandler({
apiProvider: glama,
glamaApiKey: apiKey,
})
}
// await this.postMessageToWebview({ type: "action", action: "settingsButtonClicked" }) // bad ux if user is on welcome
}
async readGlamaModels(): Promise<Record<string, ModelInfo> | undefined> {
const glamaModelsFilePath = path.join(
await this.ensureCacheDirectoryExists(),