-
Notifications
You must be signed in to change notification settings - Fork 6.5k
feat(codex): connect ChatGPT accounts with managed authentication #14290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+10,061
−280
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ee22930
feat(codex): connect ChatGPT accounts with managed authentication
juliusmarminge 5105f31
docs(codex): explain ChatGPT setup and account management
juliusmarminge 030cd15
fix(codex): keep managed runtime constants internal
juliusmarminge a2c28a2
fix(chatgpt): finish hosted onboarding callbacks and preserve managed…
juliusmarminge b93232a
test(web): rerender mocked account snapshots with React Compiler
juliusmarminge b7c34f9
test(web): remove integration-specific UI tests
juliusmarminge 6f14834
test(web): isolate existing onboarding fixture from account setup
juliusmarminge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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")!); | ||
| url.search = new URLSearchParams({ | ||
| state: request.searchParams.get("state")!, | ||
| code: "test-code", | ||
| client_id: "oaiapp_test", | ||
| }).toString(); | ||
| return url.toString(); | ||
| } | ||
|
|
||
| describe("desktop Codex callback helper", () => { | ||
| it("binds before opening sign-in, ignores a foreign response, and returns only the code callback", async () => { | ||
| const authorizationUrl = request(await freePort()); | ||
| const expected = callback(authorizationUrl); | ||
| const received = await receiveCodexAuthCallback(authorizationUrl, async () => { | ||
| const invalid = new URL(expected); | ||
| invalid.searchParams.set("state", "foreign"); | ||
| expect((await fetch(invalid)).status).toBe(400); | ||
| const response = await fetch(expected); | ||
| expect(response.headers.get("cache-control")).toBe("no-store"); | ||
| expect(await response.text()).not.toContain("test-code"); | ||
| return true; | ||
| }); | ||
| expect(received).toBe(expected); | ||
| }); | ||
| it("returns hosted web to the exact instance and environment without putting the code in its query", async () => { | ||
| const authorizationUrl = request(await freePort()); | ||
| const expected = callback(authorizationUrl); | ||
| const input = { | ||
| authorizationUrl, | ||
| returnUrl: "https://app.t3.codes/settings/providers?environmentId=remote-one&instanceId=work", | ||
| environmentId: EnvironmentId.make("remote-one"), | ||
| instanceId: ProviderInstanceId.make("work"), | ||
| flowId: "flow-one", | ||
| }; | ||
| await receiveCodexAuthCallback( | ||
| authorizationUrl, | ||
| async () => { | ||
| const response = await fetch(expected, { redirect: "manual" }); | ||
| expect(response.status).toBe(303); | ||
| const delivery = response.headers.get("location")!; | ||
| expect(new URL(delivery).searchParams.has("code")).toBe(false); | ||
| expect(readCodexAuthDelivery(delivery)?.callbackUrl).toBe(expected); | ||
| expect(readCodexAuthDelivery(delivery)?.returnUrl).toBe(input.returnUrl); | ||
| return true; | ||
| }, | ||
| (url) => codexAuthDeliveryUrl(input, url), | ||
| ); | ||
| }); | ||
| it("cancels and releases its listener so exact-port reauthorization can run again", async () => { | ||
| const authorizationUrl = request(await freePort()); | ||
| await expect( | ||
| receiveCodexAuthCallback(authorizationUrl, async () => { | ||
| cancelCodexAuthCallback(authorizationUrl); | ||
| return true; | ||
| }), | ||
| ).rejects.toThrow("cancelled"); | ||
| expect( | ||
| await receiveCodexAuthCallback(authorizationUrl, async () => { | ||
| await fetch(callback(authorizationUrl)); | ||
| return true; | ||
| }), | ||
| ).toBe(callback(authorizationUrl)); | ||
| }); | ||
| it("allows two accounts to complete independently", async () => { | ||
| const a = request(await freePort(), "a".repeat(43)); | ||
| const b = request(await freePort(), "c".repeat(43)); | ||
| const openedA = Promise.withResolvers<void>(); | ||
| const openedB = Promise.withResolvers<void>(); | ||
| const receiveA = receiveCodexAuthCallback(a, async () => { | ||
| openedA.resolve(); | ||
| await openedB.promise; | ||
| await fetch(callback(a)); | ||
| return true; | ||
| }); | ||
| const receiveB = receiveCodexAuthCallback(b, async () => { | ||
| openedB.resolve(); | ||
| await openedA.promise; | ||
| await fetch(callback(b)); | ||
| return true; | ||
| }); | ||
| expect(await Promise.all([receiveA, receiveB])).toEqual([callback(a), callback(b)]); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export { | ||
| CodexAuthCallbackError, | ||
| cancelCodexAuthCallback, | ||
| receiveCodexAuthCallback, | ||
| } from "@t3tools/shared/codexAuthCallback"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟠 High
app/DesktopClerk.ts:190A cold-launched
t3code://app/settings/providers?...callback never resumes provider setup:HostProcessArgumentsonly invokesstartProviderAuthHandoff, soproviderAuthReturnUrlis not loaded and no window is revealed until the app is already running. Apply the sameresumeProviderAuthhandling used bysecond-instancewhen processing startup arguments.🚀 Reply "fix it for me" or copy this AI Prompt for your agent: