mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 10:02:23 +00:00
feat(ai): add originator option to loginOpenAICodex
This commit is contained in:
parent
d2be6486a4
commit
693112e395
1 changed files with 7 additions and 3 deletions
|
|
@ -166,7 +166,9 @@ async function refreshAccessToken(refreshToken: string): Promise<TokenResult> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createAuthorizationFlow(): Promise<{ verifier: string; state: string; url: string }> {
|
async function createAuthorizationFlow(
|
||||||
|
originator: string = "pi",
|
||||||
|
): Promise<{ verifier: string; state: string; url: string }> {
|
||||||
const { verifier, challenge } = await generatePKCE();
|
const { verifier, challenge } = await generatePKCE();
|
||||||
const state = createState();
|
const state = createState();
|
||||||
|
|
||||||
|
|
@ -180,7 +182,7 @@ async function createAuthorizationFlow(): Promise<{ verifier: string; state: str
|
||||||
url.searchParams.set("state", state);
|
url.searchParams.set("state", state);
|
||||||
url.searchParams.set("id_token_add_organizations", "true");
|
url.searchParams.set("id_token_add_organizations", "true");
|
||||||
url.searchParams.set("codex_cli_simplified_flow", "true");
|
url.searchParams.set("codex_cli_simplified_flow", "true");
|
||||||
url.searchParams.set("originator", "pi");
|
url.searchParams.set("originator", originator);
|
||||||
|
|
||||||
return { verifier, state, url: url.toString() };
|
return { verifier, state, url: url.toString() };
|
||||||
}
|
}
|
||||||
|
|
@ -279,14 +281,16 @@ function getAccountId(accessToken: string): string | null {
|
||||||
* @param options.onManualCodeInput - Optional promise that resolves with user-pasted code.
|
* @param options.onManualCodeInput - Optional promise that resolves with user-pasted code.
|
||||||
* Races with browser callback - whichever completes first wins.
|
* Races with browser callback - whichever completes first wins.
|
||||||
* Useful for showing paste input immediately alongside browser flow.
|
* Useful for showing paste input immediately alongside browser flow.
|
||||||
|
* @param options.originator - OAuth originator parameter (defaults to "pi")
|
||||||
*/
|
*/
|
||||||
export async function loginOpenAICodex(options: {
|
export async function loginOpenAICodex(options: {
|
||||||
onAuth: (info: { url: string; instructions?: string }) => void;
|
onAuth: (info: { url: string; instructions?: string }) => void;
|
||||||
onPrompt: (prompt: OAuthPrompt) => Promise<string>;
|
onPrompt: (prompt: OAuthPrompt) => Promise<string>;
|
||||||
onProgress?: (message: string) => void;
|
onProgress?: (message: string) => void;
|
||||||
onManualCodeInput?: () => Promise<string>;
|
onManualCodeInput?: () => Promise<string>;
|
||||||
|
originator?: string;
|
||||||
}): Promise<OAuthCredentials> {
|
}): Promise<OAuthCredentials> {
|
||||||
const { verifier, state, url } = await createAuthorizationFlow();
|
const { verifier, state, url } = await createAuthorizationFlow(options.originator);
|
||||||
const server = await startLocalOAuthServer(state);
|
const server = await startLocalOAuthServer(state);
|
||||||
|
|
||||||
options.onAuth({ url, instructions: "A browser window should open. Complete login to finish." });
|
options.onAuth({ url, instructions: "A browser window should open. Complete login to finish." });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue