Adjusted Plan · Auth File Generator Automation

Bulk ChatGPT Session → Auth File Automation

Revised plan: do exactly what the generator of our mapping tool does, but automate the login/session collection, mapping, testing, and CLIProxyAPI upload. No OAuth PKCE scope expansion.

1. Corrected scope

Correction accepted: The tool must not switch to a durable OAuth PKCE/refresh-token plan. Kacher asked for automation that does exactly the generator of the existing mapping site: collect the ChatGPT session/dump shape, map it to the same auth JSON output, test, then upload.

Do

Automate login → open https://chatgpt.com/api/auth/session → collect session JSON/dump → run the generator mapper logic → upload JSON file.

Do not

Do not redesign scope around OpenAI OAuth PKCE or require refresh-token durability unless Kacher asks later.

Settings-based upload

The tool UI has settings for base_url and management key; upload code only calls the endpoint.

Implementation progress

PhaseStatusCurrent artifactNext action
Phase 1 — UI firstIn progressprojects/codex-auth-bulk-tool/public/index.htmlKacher review UI scaffold, then iterate styling/fields.
Phase 2 — Auth generator extractionStartedsrc/auth-generator.mjsAdd fixtures/tests from real sanitized dump shape.
Phase 3 — CloakBrowser loginPendingNot startedImplement after UI approval.
Phase 4 — Upload/testClient scaffoldedsrc/cliproxy-client.mjsWire UI action + test endpoint behavior.

2. Auth File Generator Logic

This is the core job to automate. The Auth File Generator accepts one sensitive ChatGPT/session dump, extracts a fixed set of fields, builds a Codex auth JSON, marks missing fields, then copy/download/upload the clean JSON.

Generator input

The UI says: paste or collect a single sensitive dump containing fields like WARNING_BANNER, accessToken, and sessionToken. The parser is forgiving: it strips code fences, extracts the first JSON object, normalizes smart quotes, and removes trailing commas.

// parseLooseJson() behavior
normalize smart quotes / NBSP
strip ```json fences
slice first { ... last }
JSON.parse(), retry after removing trailing commas

Generator output

The output is a clean JSON object with the old CLIProxyAPI Codex auth-file shape. Missing values are filled as __MISSING__ and highlighted yellow in the preview.

{
  "access_token": "...",
  "account_id": "...",
  "disabled": false,
  "email": "...",
  "expired": "...",
  "id_token": "__MISSING__",
  "last_refresh": "...",
  "refresh_token": "__MISSING__",
  "type": "codex"
}

Exact mapping contract

Output auth fieldSource in dumpFallback / behavior
access_tokendump.accessTokenIf empty/missing → __MISSING__ and mark missing.
account_iddump.account.idIf empty/missing → __MISSING__.
disabledNot read from dumpAlways false, because the generator assumes a usable account.
emaildump.user.email or dump.account.emailIf both missing → __MISSING__.
expireddump.expiresIf missing → __MISSING__.
id_tokendump.idToken or dump.id_tokensessionToken is not treated as id_token. Missing is surfaced.
last_refreshdump.last_refresh or dump.exported_atIf missing → __MISSING__.
refresh_tokendump.refreshToken or dump.refresh_tokensessionToken is not treated as refresh_token. Missing is surfaced.
typeConstantAlways codex.

File naming contract

The generator download uses safeFileNameFromAuth():

codex-<sanitized email>-plus.json

// sanitize rule
String(auth.email || 'auth')
  .replace(/^<mailto:([^|>]+)\|([^>]+)>$/, '$2')
  .replace(/[^a-zA-Z0-9@._-]+/g, '_')

How automation uses this generator

Collect dump automatically
Instead of manual paste, CloakBrowser logs in and fetches https://chatgpt.com/api/auth/session inside the authenticated context.
Normalize dump
Apply the same forgiving JSON parser only if the collected payload is text; if fetch returns JSON directly, pass it into the mapper.
Run Auth File Generator
Use the Auth File Generator mapping table above. Do not invent missing fields and do not reinterpret sessionToken as id_token/refresh_token.
Gate upload
If required fields are missing, show a yellow warning exactly like the generator preview and apply the tool’s upload policy: block upload by default or allow only if the operator enables “upload with missing fields”.
Upload generated JSON
Use the configured base_url and management key to upload the generated file to CLIProxyAPI.

3. Evidence & source references

TopicSource evidenceDecision
Existing mapper behaviorobject-token-mapper-page/index.html the generator implements buildFromSensitiveDumpObject(). It maps dump fields such as accessToken, account.id, user.email, expires, idToken, refreshToken into the output auth JSON.Reuse this logic as the core mapper library.
Upload endpointCLIProxyAPI/internal/api/server.go registers POST /v0/management/auth-files. internal/api/handlers/management/auth_files.go implements UploadAuthFile().Use endpoint directly; no browser upload click needed.
Upload payloadCli-Proxy-API-Management-Center/src/services/api/authFiles.ts appends files via FormData field file.Tool uploads multipart files using field name file.
Management settingssrc/services/api/client.ts computes base_url + /v0/management and sends Authorization: Bearer <managementKey>.UI settings must expose base_url and management key.
Testing uploaded files/v0/management/api-call supports auth_index and $TOKEN$ replacement; quota code calls https://chatgpt.com/backend-api/wham/usage.After upload, list auth files, get auth_index, test via API-call or configured test endpoint.

4. Phase 1 must be UI design

New priority: Start with a clean standalone local HTML UI, because this is an operator workflow. The CLI engine sits behind the UI, but the user experience is designed first.

Settings panel

  • CLIProxyAPI base_url
  • Management key input, masked
  • Upload mode: dry-run / upload-on-pass
  • Test endpoint config
  • CloakBrowser profile/session options

Batch runner

  • Paste accounts: username | password | TOTP secret
  • Per-account progress timeline
  • Status table: login, session, map, test, upload, cleanup
  • Redacted logs
  • Download JSON/CSV report

5. Corrected end-to-end flow

1. Load operator settings
User sets CLIProxyAPI base_url and management key in the tool settings. Store locally only if user explicitly enables encrypted save.
2. Parse account lines
Each line: username | password | TOTP secret. Validate that the third field is a TOTP secret; never accept pre-generated 6-digit codes and never echo secrets.
3. Launch CloakBrowser private profile
Use CloakBrowser for better anti-detect. Create a fresh temporary browser context/profile per account.
4. Login ChatGPT
Open ChatGPT login, fill username/password, and if 2FA appears generate the 6-digit code automatically from the provided TOTP secret.
5. Get session dump
Open or fetch https://chatgpt.com/api/auth/session inside the authenticated browser context.
6. Run Auth File Generator
Use the standalone Auth File Generator contract documented above. Missing fields become __MISSING__ and are surfaced exactly like the generator preview, not silently invented.
7. Test generated auth file
Test locally or via CLIProxyAPI /api-call depending on available output fields. Mark pass/fail with clear reason.
8. Upload if pass
POST the generated JSON to {base_url}/v0/management/auth-files using the configured management key.
9. Clear footprint
Close context, clear cookies/storage/cache, delete temporary profile directory, delete temp auth JSON unless user chooses keep.

6. 2FA: TOTP secret only

TOTP secret path

Field 3 is always a TOTP secret. The tool uses a standard TOTP library such as otplib to generate the current 6-digit confirmation code automatically.

import { authenticator } from 'otplib';
const code = authenticator.generate(secret);

No manual-code path

There is no supported case for pre-entered 6-digit codes or manual prompts. If the TOTP secret is missing/invalid and ChatGPT asks for 2FA, the row fails with a clear error.

email | password | JBSWY3DPEHPK3PXP
# invalid: email | password | 123456
# invalid: email | password |
Safety: TOTP secrets are never logged. They live in memory during the account run and are discarded after cleanup.

7. Session/cookie/footprint cleanup

AreaCleanup actionWhy
Browser contextClose page/context after each account.Prevents account cross-contamination.
Cookies/storageClear cookies, localStorage, sessionStorage, IndexedDB/cache where supported.Removes ChatGPT session state.
Temporary profileUse a per-account temp CloakBrowser profile and delete the directory after run.Reduces browser fingerprint/session residue.
Auth JSON temp fileWrite with 0600, upload, then delete unless --keep-files.Limits token exposure on disk.
Logs/reportRedact password, 2FA secret, access tokens, session JSON.Operator can debug without leaking credentials.

8. Revised phases & roadmap

PhaseScopeDeliverableExit criteria
Phase 1UI firstStandalone local HTML design with settings, account input, progress table, report export, and clear status taxonomy.Kacher approves UX before engine work.
Phase 2Auth generator extractionShared JS library for Session Dump → Auth JSON: parse session dump → auth JSON + missing-field report.Given the same dump, output matches the current generator logic.
Phase 3CloakBrowser login prototypeSingle-account login, TOTP-secret-only 2FA handling, fetch /api/auth/session, cleanup footprint.One account runs end-to-end without retaining session residue.
Phase 4Upload/test integrationSettings-based CLIProxyAPI uploader and test runner.Generated file uploads through endpoint and appears in Auth Files.
Phase 5Batch workflowSerial queue, retry rules, fail-fast on missing/invalid TOTP secret, redacted report.Batch handles mixed success/failure safely.
Phase 6Packaging & docsREADME, install script, examples, troubleshooting guide, optional AppleScript fallback note.Repeatable run on Kacher’s machine.

9. Concrete deliverables

UI deliverable

  • Standalone local HTML app
  • Settings modal: base_url + management key
  • Account paste area
  • Per-account progress cards
  • Missing-field display exactly like the generator preview
  • Download report

Engine deliverable

  • CloakBrowser automation runner
  • TOTP-secret-only 6-digit generator
  • Session fetcher for /api/auth/session
  • Auth File Generator library
  • CLIProxyAPI uploader
  • Cleanup manager

Verified upload API

# Upload generated auth file using tool settings
curl -sS -X POST "$BASE_URL/v0/management/auth-files" \
  -H "Authorization: Bearer $MANAGEMENT_KEY" \
  -F "file=@generated-auth.json;type=application/json"

# Raw JSON alternative
curl -sS -X POST "$BASE_URL/v0/management/auth-files?name=generated-auth.json" \
  -H "Authorization: Bearer $MANAGEMENT_KEY" \
  -H "Content-Type: application/json" \
  --data-binary @generated-auth.json