Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(codex): connect ChatGPT accounts with managed authentication #14290

Mergedjuliusmarmingemerged 7 commits intomain fromrefs/pull/14290/headmerged by juliusmarminge View on GitHub

Showing 120 changed files with 117 additions and 0 deletions (loading 117).

x
0 of 120 viewed, 120 left
112 additions and 0 deletionsapps/desktop/src/app/CodexAuthCallback.test.tsAdded
View file
@@ -0,0 +1,112 @@
+// @effect-diagnostics nodeBuiltinImport:off globalFetch:off - Tests exercise the real native loopback listener without an OpenAI account.
+import * as NodeHttp from "node:http";
+import { describe, expect, it } from "vite-plus/test";
+import { codexAuthDeliveryUrl, readCodexAuthDelivery } from "@t3tools/shared/codexAuthHandoff";
+import { EnvironmentId, ProviderInstanceId } from "@t3tools/contracts";
+import { receiveCodexAuthCallback, cancelCodexAuthCallback } from "./CodexAuthCallback.ts";
+​
+async function freePort() {
+ const server = NodeHttp.createServer();
+ await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
+ const address = server.address();
+ if (!address || typeof address === "string") throw new Error("address");
+ await new Promise<void>((resolve) => server.close(() => resolve()));
+ return address.port;
+}
+function request(port: number, state = "a".repeat(43)) {
+ const url = new URL("https://auth.openai.com/api/accounts/authorize");
+ url.search = new URLSearchParams({
+ client_id: "dynamic_agent_client",
+ response_type: "code",
+ redirect_uri: `http://127.0.0.1:${port}/auth/callback`,
+ state,
+ code_challenge_method: "S256",
+ code_challenge: "b".repeat(43),
+ }).toString();
+ return url.toString();
+}
+function callback(authorizationUrl: string) {
+ const request = new URL(authorizationUrl);
+ const url = new URL(request.searchParams.get("redirect_uri")!);