mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-15 03:01:02 +00:00
openai-codex: classify auth and runtime failures
This commit is contained in:
@@ -10,6 +10,41 @@ import {
|
||||
|
||||
const manualInputPromptMessage = "Paste the authorization code (or full redirect URL):";
|
||||
const openAICodexOAuthOriginator = "openclaw";
|
||||
const OPENAI_CODEX_OAUTH_REQUIRED_SCOPES = [
|
||||
"openid",
|
||||
"profile",
|
||||
"email",
|
||||
"offline_access",
|
||||
"model.request",
|
||||
"api.responses.write",
|
||||
] as const;
|
||||
|
||||
function normalizeOpenAICodexAuthorizeUrl(rawUrl: string): string {
|
||||
const trimmed = rawUrl.trim();
|
||||
if (!trimmed) {
|
||||
return rawUrl;
|
||||
}
|
||||
try {
|
||||
const url = new URL(trimmed);
|
||||
if (!/openai\.com$/i.test(url.hostname) || !/\/oauth\/authorize$/i.test(url.pathname)) {
|
||||
return rawUrl;
|
||||
}
|
||||
|
||||
const existing = new Set(
|
||||
(url.searchParams.get("scope") ?? "")
|
||||
.split(/\s+/)
|
||||
.map((scope) => scope.trim())
|
||||
.filter(Boolean),
|
||||
);
|
||||
for (const scope of OPENAI_CODEX_OAUTH_REQUIRED_SCOPES) {
|
||||
existing.add(scope);
|
||||
}
|
||||
url.searchParams.set("scope", Array.from(existing).join(" "));
|
||||
return url.toString();
|
||||
} catch {
|
||||
return rawUrl;
|
||||
}
|
||||
}
|
||||
|
||||
export async function loginOpenAICodexOAuth(params: {
|
||||
prompter: WizardPrompter;
|
||||
@@ -60,7 +95,11 @@ export async function loginOpenAICodexOAuth(params: {
|
||||
});
|
||||
|
||||
const creds = await loginOpenAICodex({
|
||||
onAuth: baseOnAuth,
|
||||
onAuth: async (event) =>
|
||||
await baseOnAuth({
|
||||
...event,
|
||||
url: normalizeOpenAICodexAuthorizeUrl(event.url),
|
||||
}),
|
||||
onPrompt,
|
||||
originator: openAICodexOAuthOriginator,
|
||||
onManualCodeInput: isRemote
|
||||
|
||||
Reference in New Issue
Block a user