refactor: dedupe OAuth flow handlers

This commit is contained in:
Peter Steinberger
2026-01-13 05:13:01 +00:00
parent d8f14078f0
commit 01776e0569
4 changed files with 140 additions and 57 deletions

View File

@@ -125,13 +125,19 @@ export async function loginChutes(params: {
app: ChutesOAuthAppConfig;
manual?: boolean;
timeoutMs?: number;
createPkce?: typeof generateChutesPkce;
createState?: () => string;
onAuth: (event: { url: string }) => Promise<void>;
onPrompt: (prompt: OAuthPrompt) => Promise<string>;
onProgress?: (message: string) => void;
fetchFn?: typeof fetch;
}): Promise<OAuthCredentials> {
const { verifier, challenge } = generateChutesPkce();
const state = randomBytes(16).toString("hex");
const createPkce = params.createPkce ?? generateChutesPkce;
const createState =
params.createState ?? (() => randomBytes(16).toString("hex"));
const { verifier, challenge } = createPkce();
const state = createState();
const timeoutMs = params.timeoutMs ?? 3 * 60 * 1000;
const url = buildAuthorizeUrl({