Repository navigation
feat(ai): migrate ChatGPT authentication and inference #291
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
Pepps233
merged 10 commits into
fix/remove-radius-integration
from
feat/chatgpt-public-auth
Oct 27, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
980d88b
feat(ai): register Diffex ChatGPT sessions
Pepps233 a9a58e4
feat(ai): use public ChatGPT inference
Pepps233 466fd4b
fix(ai): harden ChatGPT session lifecycle
Pepps233 7ef46c9
fix(coding-agent): verify ChatGPT login label
Pepps233 6494e88
fix(ai): synchronize provider validation
Pepps233 9426827
fix(coding-agent): synchronize secure fixtures
Pepps233 8614540
fix(coding-agent): isolate credential fixtures
Pepps233 9667dd7
fix(ai): verify registration path boundaries
Pepps233 bf85405
fix(coding-agent): protect example auth storage
Pepps233 cd14fd3
fix(coding-agent): make file mode explicit
Pepps233 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,7 @@ | ||
| /** A provider confirmed that this renewable session cannot be used again. */ | ||
| export class OAuthSessionExpiredError extends Error { | ||
| constructor(message: string) { | ||
| super(message); | ||
| this.name = "OAuthSessionExpiredError"; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| import { randomUUID } from "node:crypto"; | ||
| import { linkSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs"; | ||
| import { homedir } from "node:os"; | ||
| import { join } from "node:path"; | ||
|
|
||
| export interface ChatGPTRegistration { | ||
| clientId: string; | ||
| subject?: string; | ||
| email?: string; | ||
| idToken?: string; | ||
| scopes?: string[]; | ||
| } | ||
|
|
||
| /** Registration metadata survives logout; renewable tokens live in the credential store. */ | ||
| export class ChatGPTRegistrationStore { | ||
| private readonly directory: string; | ||
|
|
||
| constructor() { | ||
| const configured = process.env.DIFFEX_CODING_AGENT_DIR; | ||
| const directory = configured?.startsWith("~/") ? join(homedir(), configured.slice(2)) : configured; | ||
| this.directory = join(directory || join(homedir(), ".diffex", "agent"), "chatgpt"); | ||
| mkdirSync(this.directory, { recursive: true, mode: 0o700 }); | ||
| } | ||
|
|
||
| hostId(): string { | ||
| const path = join(this.directory, "host"); | ||
| const temporary = join(this.directory, `${randomUUID()}.tmp`); | ||
| // Publish a complete file exclusively when processes first sign in concurrently. | ||
| writeFileSync(temporary, `urn:uuid:${randomUUID()}`, { mode: 0o600, flag: "wx" }); | ||
|
Pepps233 marked this conversation as resolved.
Dismissed
|
||
| try { | ||
| try { | ||
| linkSync(temporary, path); | ||
|
Pepps233 marked this conversation as resolved.
Dismissed
Pepps233 marked this conversation as resolved.
Dismissed
|
||
| } catch (error) { | ||
| if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error; | ||
| } | ||
| const host = readFileSync(path, "utf8").trim(); | ||
|
Pepps233 marked this conversation as resolved.
Dismissed
|
||
| if (!/^urn:uuid:[0-9a-f-]{36}$/.test(host)) throw new Error("Invalid saved ChatGPT host identity"); | ||
| return host; | ||
| } finally { | ||
| unlinkSync(temporary); | ||
|
Pepps233 marked this conversation as resolved.
Dismissed
|
||
| } | ||
| } | ||
|
|
||
| list(): ChatGPTRegistration[] { | ||
| return readdirSync(this.directory) | ||
|
Pepps233 marked this conversation as resolved.
Dismissed
|
||
| .filter((name) => name.endsWith(".json")) | ||
| .map((name) => { | ||
| const value = JSON.parse(readFileSync(join(this.directory, name), "utf8")) as ChatGPTRegistration; | ||
|
Pepps233 marked this conversation as resolved.
Dismissed
|
||
| if ( | ||
| !/^oaiapp_[\w-]+$/.test(value.clientId) || | ||
| (value.subject !== undefined && (typeof value.subject !== "string" || !value.subject)) || | ||
| (value.email !== undefined && typeof value.email !== "string") || | ||
| (value.idToken !== undefined && typeof value.idToken !== "string") || | ||
| (value.scopes !== undefined && | ||
| (!Array.isArray(value.scopes) || !value.scopes.every((scope) => typeof scope === "string"))) | ||
| ) { | ||
| throw new Error("Invalid saved ChatGPT registration"); | ||
| } | ||
| return value; | ||
| }); | ||
| } | ||
|
|
||
| save(registration: ChatGPTRegistration): void { | ||
| if (!/^oaiapp_[\w-]+$/.test(registration.clientId)) throw new Error("Invalid issued ChatGPT client ID"); | ||
| const temporary = join(this.directory, `${randomUUID()}.tmp`); | ||
| try { | ||
| writeFileSync(temporary, JSON.stringify(registration), { mode: 0o600, flag: "wx" }); | ||
|
Pepps233 marked this conversation as resolved.
Dismissed
Pepps233 marked this conversation as resolved.
Dismissed
|
||
| renameSync(temporary, join(this.directory, `${registration.clientId}.json`)); | ||
|
Pepps233 marked this conversation as resolved.
Dismissed
Pepps233 marked this conversation as resolved.
Dismissed
|
||
| } finally { | ||
| rmSync(temporary, { force: true }); | ||
|
Pepps233 marked this conversation as resolved.
Dismissed
|
||
| } | ||
| } | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.