Skip to content

Commit e805ffd

Browse files
authored
refactor(openai): centralize codex oauth flow (#87411)
1 parent 53704b2 commit e805ffd

7 files changed

Lines changed: 452 additions & 1416 deletions

File tree

extensions/openai/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export {
1010
OPENAI_DEFAULT_TTS_VOICE,
1111
} from "./default-models.js";
1212
export { buildOpenAICodexProvider } from "./openai-codex-catalog.js";
13+
export { loginOpenAICodexOAuth } from "./openai-codex-oauth.runtime.js";
14+
export { refreshOpenAICodexToken } from "./openai-codex-provider.runtime.js";
1315
export { buildOpenAICodexProviderPlugin } from "./openai-codex-provider.js";
1416
export { buildOpenAIProvider } from "./openai-provider.js";
1517
export { buildOpenAIRealtimeTranscriptionProvider } from "./realtime-transcription-provider.js";

extensions/openai/openai-codex-oauth.runtime.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ export async function loginOpenAICodexOAuth(params: {
257257
oauth: ProviderAuthContext["oauth"];
258258
isRemote: boolean;
259259
openUrl: (url: string) => Promise<void>;
260+
signal?: AbortSignal;
261+
onManualCodeInput?: () => Promise<string>;
260262
localBrowserMessage?: string;
261263
}): Promise<OAuthCredentials | null> {
262264
const { prompter, runtime, isRemote, openUrl, localBrowserMessage } = params;
@@ -324,16 +326,19 @@ export async function loginOpenAICodexOAuth(params: {
324326
onAuth,
325327
onPrompt,
326328
originator: openAICodexOAuthOriginator,
327-
onManualCodeInput: createManualCodeInputHandler({
328-
isRemote,
329-
onPrompt,
330-
runtime,
331-
updateProgress,
332-
stopProgress,
333-
waitForLoginToSettle,
334-
hasBrowserAuthStarted: () => browserAuthStarted,
335-
}),
329+
onManualCodeInput:
330+
params.onManualCodeInput ??
331+
createManualCodeInputHandler({
332+
isRemote,
333+
onPrompt,
334+
runtime,
335+
updateProgress,
336+
stopProgress,
337+
waitForLoginToSettle,
338+
hasBrowserAuthStarted: () => browserAuthStarted,
339+
}),
336340
onProgress: (msg: string) => updateProgress(msg),
341+
signal: params.signal,
337342
});
338343
stopProgress("OpenAI OAuth complete");
339344
return creds ?? null;

extensions/openai/openai-codex-provider.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,20 @@ async function refreshOpenAICodexOAuthCredential(cred: OAuthCredential) {
411411
}
412412
}
413413

414-
async function runOpenAICodexOAuth(ctx: ProviderAuthContext) {
414+
type OpenAICodexOAuthContext = ProviderAuthContext & {
415+
signal?: AbortSignal;
416+
onManualCodeInput?: () => Promise<string>;
417+
};
418+
419+
async function runOpenAICodexOAuth(ctx: OpenAICodexOAuthContext) {
415420
const creds = await loginOpenAICodexOAuth({
416421
prompter: ctx.prompter,
417422
runtime: ctx.runtime,
418423
oauth: ctx.oauth,
419424
isRemote: ctx.isRemote,
420425
openUrl: ctx.openUrl,
426+
signal: ctx.signal,
427+
onManualCodeInput: ctx.onManualCodeInput,
421428
localBrowserMessage: "Complete sign-in in browser…",
422429
});
423430
if (!creds) {

0 commit comments

Comments
 (0)