mirror of
https://gitea.toothfairyai.com/ToothFairyAI/tf_code.git
synced 2026-04-05 16:36:52 +00:00
sync
This commit is contained in:
@@ -2,11 +2,12 @@ import { generatePKCE } from "@openauthjs/openauth/pkce"
|
||||
import { Global } from "../global"
|
||||
import path from "path"
|
||||
import fs from "fs/promises"
|
||||
import type { BunFile } from "bun"
|
||||
|
||||
export namespace AuthAnthropic {
|
||||
const CLIENT_ID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e"
|
||||
|
||||
const file = Bun.file(path.join(Global.Path.data, "auth", "anthropic.json"))
|
||||
|
||||
export async function authorize() {
|
||||
const pkce = await generatePKCE()
|
||||
const url = new URL("https://claude.ai/oauth/authorize", import.meta.url)
|
||||
@@ -47,13 +48,11 @@ export namespace AuthAnthropic {
|
||||
}),
|
||||
})
|
||||
if (!result.ok) throw new ExchangeFailed()
|
||||
const file = Bun.file(path.join(Global.Path.data, "anthropic.json"))
|
||||
await Bun.write(file, result)
|
||||
await fs.chmod(file.name!, 0o600)
|
||||
}
|
||||
|
||||
export async function access() {
|
||||
const file = Bun.file(path.join(Global.Path.data, "anthropic.json"))
|
||||
if (!(await file.exists())) return
|
||||
const result = await file.json()
|
||||
const refresh = result.refresh_token
|
||||
|
||||
20
packages/opencode/src/auth/keys.ts
Normal file
20
packages/opencode/src/auth/keys.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import path from "path"
|
||||
import { Global } from "../global"
|
||||
import fs from "fs/promises"
|
||||
|
||||
export namespace AuthKeys {
|
||||
const file = Bun.file(path.join(Global.Path.data, "auth", "keys.json"))
|
||||
|
||||
export async function get() {
|
||||
return file
|
||||
.json()
|
||||
.catch(() => ({}))
|
||||
.then((x) => x as Record<string, string>)
|
||||
}
|
||||
|
||||
export async function set(key: string, value: string) {
|
||||
const env = await get()
|
||||
await Bun.write(file, JSON.stringify({ ...env, [key]: value }))
|
||||
await fs.chmod(file.name!, 0o600)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user