mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
Merge pull request #104 from diegosouzapw/fix-issues-101-103
Fix OAuth client_secret issues (#103) & Codex Business quotas (#101)
This commit is contained in:
@@ -486,12 +486,44 @@ async function getClaudeUsage(accessToken) {
|
||||
*/
|
||||
async function getCodexUsage(accessToken) {
|
||||
try {
|
||||
let accountId = null;
|
||||
try {
|
||||
const accountsRes = await fetch("https://chatgpt.com/backend-api/accounts/check/v4", {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
Accept: "application/json",
|
||||
},
|
||||
});
|
||||
if (accountsRes.ok) {
|
||||
const accountsData = await accountsRes.json();
|
||||
if (accountsData.accounts) {
|
||||
const accountsArray = Object.values(accountsData.accounts) as any[];
|
||||
const targetWorkspace =
|
||||
accountsArray.find((a) => a.account?.plan_type === "biz") ||
|
||||
accountsArray.find((a) => a.account?.plan_type !== "free") ||
|
||||
accountsArray.find((a) => a.is_default) ||
|
||||
accountsArray[0];
|
||||
if (targetWorkspace && targetWorkspace.account?.id) {
|
||||
accountId = targetWorkspace.account.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn("Could not fetch ChatGPT accounts for quota:", err);
|
||||
}
|
||||
|
||||
const headers: Record<string, string> = {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
Accept: "application/json",
|
||||
};
|
||||
if (accountId) {
|
||||
headers["chatgpt-account-id"] = accountId;
|
||||
}
|
||||
|
||||
const response = await fetch(CODEX_CONFIG.usageUrl, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
Accept: "application/json",
|
||||
},
|
||||
headers,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
@@ -216,7 +216,12 @@ export function normalizePlanTier(plan) {
|
||||
return { key: "enterprise", label: "Enterprise", variant: "info", rank: 6, raw };
|
||||
}
|
||||
|
||||
if (upper.includes("BUSINESS") || upper.includes("TEAM") || upper.includes("STANDARD")) {
|
||||
if (
|
||||
upper.includes("BUSINESS") ||
|
||||
upper.includes("TEAM") ||
|
||||
upper.includes("STANDARD") ||
|
||||
upper.includes("BIZ")
|
||||
) {
|
||||
return { key: "business", label: "Business", variant: "warning", rank: 5, raw };
|
||||
}
|
||||
|
||||
|
||||
@@ -16,19 +16,24 @@ export const antigravity = {
|
||||
return `${config.authorizeUrl}?${params.toString()}`;
|
||||
},
|
||||
exchangeToken: async (config, code, redirectUri) => {
|
||||
const bodyParams: Record<string, string> = {
|
||||
grant_type: "authorization_code",
|
||||
client_id: config.clientId,
|
||||
code: code,
|
||||
redirect_uri: redirectUri,
|
||||
};
|
||||
|
||||
if (config.clientSecret) {
|
||||
bodyParams.client_secret = config.clientSecret;
|
||||
}
|
||||
|
||||
const response = await fetch(config.tokenUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
Accept: "application/json",
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
grant_type: "authorization_code",
|
||||
client_id: config.clientId,
|
||||
client_secret: config.clientSecret,
|
||||
code: code,
|
||||
redirect_uri: redirectUri,
|
||||
}),
|
||||
body: new URLSearchParams(bodyParams),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
@@ -16,19 +16,24 @@ export const gemini = {
|
||||
return `${config.authorizeUrl}?${params.toString()}`;
|
||||
},
|
||||
exchangeToken: async (config, code, redirectUri) => {
|
||||
const bodyParams: Record<string, string> = {
|
||||
grant_type: "authorization_code",
|
||||
client_id: config.clientId,
|
||||
code: code,
|
||||
redirect_uri: redirectUri,
|
||||
};
|
||||
|
||||
if (config.clientSecret) {
|
||||
bodyParams.client_secret = config.clientSecret;
|
||||
}
|
||||
|
||||
const response = await fetch(config.tokenUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
Accept: "application/json",
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
grant_type: "authorization_code",
|
||||
client_id: config.clientId,
|
||||
client_secret: config.clientSecret,
|
||||
code: code,
|
||||
redirect_uri: redirectUri,
|
||||
}),
|
||||
body: new URLSearchParams(bodyParams),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
@@ -14,22 +14,31 @@ export const iflow = {
|
||||
return `${config.authorizeUrl}?${params.toString()}`;
|
||||
},
|
||||
exchangeToken: async (config, code, redirectUri) => {
|
||||
const basicAuth = Buffer.from(`${config.clientId}:${config.clientSecret}`).toString("base64");
|
||||
const headers: Record<string, string> = {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
Accept: "application/json",
|
||||
};
|
||||
|
||||
if (config.clientSecret) {
|
||||
const basicAuth = Buffer.from(`${config.clientId}:${config.clientSecret}`).toString("base64");
|
||||
headers.Authorization = `Basic ${basicAuth}`;
|
||||
}
|
||||
|
||||
const bodyParams: Record<string, string> = {
|
||||
grant_type: "authorization_code",
|
||||
code: code,
|
||||
redirect_uri: redirectUri,
|
||||
client_id: config.clientId,
|
||||
};
|
||||
|
||||
if (config.clientSecret) {
|
||||
bodyParams.client_secret = config.clientSecret;
|
||||
}
|
||||
|
||||
const response = await fetch(config.tokenUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
Accept: "application/json",
|
||||
Authorization: `Basic ${basicAuth}`,
|
||||
},
|
||||
body: new URLSearchParams({
|
||||
grant_type: "authorization_code",
|
||||
code: code,
|
||||
redirect_uri: redirectUri,
|
||||
client_id: config.clientId,
|
||||
client_secret: config.clientSecret,
|
||||
}),
|
||||
headers: headers,
|
||||
body: new URLSearchParams(bodyParams),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
|
||||
Reference in New Issue
Block a user