mirror of
https://github.com/decolua/9router.git
synced 2026-05-08 12:01:28 +00:00
fix(cline): use workos auth token shape
Made-with: Cursor
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { BaseExecutor } from "./base.js";
|
||||
import { PROVIDERS, OAUTH_ENDPOINTS } from "../config/constants.js";
|
||||
import { buildClineHeaders } from "../../src/shared/utils/clineAuth.js";
|
||||
|
||||
export class DefaultExecutor extends BaseExecutor {
|
||||
constructor(provider) {
|
||||
@@ -65,6 +66,8 @@ export class DefaultExecutor extends BaseExecutor {
|
||||
if (credentials.providerSpecificData?.orgId) {
|
||||
headers["X-Kilocode-OrganizationID"] = credentials.providerSpecificData.orgId;
|
||||
}
|
||||
} else if (this.provider === "cline") {
|
||||
Object.assign(headers, buildClineHeaders(credentials.apiKey || credentials.accessToken));
|
||||
} else {
|
||||
headers["Authorization"] = `Bearer ${credentials.apiKey || credentials.accessToken}`;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { PROVIDERS } from "../config/constants.js";
|
||||
import { buildClineHeaders } from "../../src/shared/utils/clineAuth.js";
|
||||
|
||||
const OPENAI_COMPATIBLE_PREFIX = "openai-compatible-";
|
||||
const OPENAI_COMPATIBLE_DEFAULTS = {
|
||||
@@ -285,6 +286,10 @@ export function buildProviderHeaders(provider, credentials, stream = true, body
|
||||
case "openrouter":
|
||||
headers["Authorization"] = `Bearer ${credentials.apiKey || credentials.accessToken}`;
|
||||
break;
|
||||
|
||||
case "cline":
|
||||
Object.assign(headers, buildClineHeaders(credentials.apiKey || credentials.accessToken));
|
||||
break;
|
||||
|
||||
case "glm":
|
||||
case "kimi":
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
CLINE_CONFIG,
|
||||
KILOCODE_CONFIG,
|
||||
} from "@/lib/oauth/constants/oauth";
|
||||
import { buildClineHeaders } from "@/shared/utils/clineAuth";
|
||||
|
||||
// OAuth provider test endpoints
|
||||
const OAUTH_TEST_CONFIG = {
|
||||
@@ -58,19 +59,10 @@ const OAUTH_TEST_CONFIG = {
|
||||
};
|
||||
|
||||
async function probeClineAccessToken(accessToken) {
|
||||
const res = await fetch("https://api.cline.bot/api/v1/chat/completions", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
"Content-Type": "application/json",
|
||||
"HTTP-Referer": "https://cline.bot",
|
||||
"X-Title": "Cline",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
model: "cl/anthropic/claude-sonnet-4-20250514",
|
||||
messages: [{ role: "user", content: "test" }],
|
||||
max_tokens: 1,
|
||||
stream: false,
|
||||
const res = await fetch("https://api.cline.bot/api/v1/users/me", {
|
||||
method: "GET",
|
||||
headers: buildClineHeaders(accessToken, {
|
||||
Accept: "application/json",
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
37
src/shared/utils/clineAuth.js
Normal file
37
src/shared/utils/clineAuth.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import pkg from "../../../package.json" with { type: "json" };
|
||||
|
||||
const APP_VERSION = pkg.version || "0.0.0";
|
||||
|
||||
export function getClineAccessToken(token) {
|
||||
if (typeof token !== "string") return "";
|
||||
const trimmed = token.trim();
|
||||
if (!trimmed) return "";
|
||||
return trimmed.startsWith("workos:") ? trimmed : `workos:${trimmed}`;
|
||||
}
|
||||
|
||||
export function getClineAuthorizationHeader(token) {
|
||||
const accessToken = getClineAccessToken(token);
|
||||
return accessToken ? `Bearer ${accessToken}` : "";
|
||||
}
|
||||
|
||||
export function buildClineHeaders(token, extraHeaders = {}) {
|
||||
const authorization = getClineAuthorizationHeader(token);
|
||||
const headers = {
|
||||
"HTTP-Referer": "https://cline.bot",
|
||||
"X-Title": "Cline",
|
||||
"User-Agent": `9Router/${APP_VERSION}`,
|
||||
"X-PLATFORM": process.platform || "unknown",
|
||||
"X-PLATFORM-VERSION": process.version || "unknown",
|
||||
"X-CLIENT-TYPE": "9router",
|
||||
"X-CLIENT-VERSION": APP_VERSION,
|
||||
"X-CORE-VERSION": APP_VERSION,
|
||||
"X-IS-MULTIROOT": "false",
|
||||
...extraHeaders,
|
||||
};
|
||||
|
||||
if (authorization) {
|
||||
headers.Authorization = authorization;
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
Reference in New Issue
Block a user