受此帖子的启发
为了那些不愿信任任何Chrome扩展程序的用户,我让AI生成了一段适用于Chrome或Firefox控制台(按F12打开)的代码,它能实现相同的功能,即生成auth.json文件。
登录后在 chatgpt.com 上使用
fetch('https://chatgpt.com/api/auth/session')
.then(res => res.json())
.then(session => {
if (!session || !session.accessToken) {
alert("You are not logged into ChatGPT or failed to fetch the session!");
return;
}
// Extract data from the session
const accountId = session.account?.id || '';
const email = session.user?.email || '';
const planType = session.account?.planType || 'free';
const iat = Math.floor(Date.now() / 1000);
const exp = session.expires ? Math.floor(new Date(session.expires).getTime() / 1000) : iat + (30 * 24 * 3600);
// Build a Fake (Synthetic) id_token for Codex
const jwtHeader = { alg: 'none', typ: 'JWT', cpa_synthetic: true };
const jwtPayload = {
iat, exp,
"https://api.openai.com/auth": {
chatgpt_account_id: accountId,
chatgpt_plan_type: planType,
chatgpt_user_id: session.user?.id || '',
user_id: session.user?.id || ''
},
email
};
const base64UrlEncode = (obj) => {
const str = JSON.stringify(obj);
const base64 = btoa(unescape(encodeURIComponent(str)));
return base64.replace(/=/g, '').replace(/\+/g, '-').replace(/\//g, '_');
};
const syntheticIdToken = `${base64UrlEncode(jwtHeader)}.${base64UrlEncode(jwtPayload)}.synthetic`;
// Build the final auth.json structure
const authConfig = {
auth_mode: "chatgpt",
OPENAI_API_KEY: null,
tokens: {
id_token: syntheticIdToken,
access_token: session.accessToken,
refresh_token: session.sessionToken || "placeholder", // ChatGPT uses sessionToken here
account_id: accountId
},
last_refresh: new Date().toISOString()
};
const jsonString = JSON.stringify(authConfig, null, 2);
// Trigger the download of auth.json
const blob = new Blob([jsonString], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'auth.json';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
console.log("✅ auth.json has been successfully generated and downloaded!");
})
.catch(err => console.error("❌ An error occurred:", err));
将下载的文件放到 Codex 认证目录(建议先备份再覆盖):
| 系统 | 路径 |
|---|---|
| Windows | %USERPROFILE%\.codex\auth.json |
| macOS / Linux | ~/.codex/auth.json |
# Windows
New-Item -ItemType Directory -Force -Path "env:USERPROFILE\.codex\auth.json"
# macOS / Linux
mkdir -p ~/.codex
cp ~/Downloads/auth.json ~/.codex/auth.json
chmod 600 ~/.codex/auth.json
在终端运行 Codex,确认不再弹出手机号验证。【Codex APP 重启即可】
