| 229 | } |
| 230 | |
| 231 | function parseCodexIdToken(idToken: string): { |
| 232 | email?: string |
| 233 | chatgpt_plan_type?: string |
| 234 | chatgpt_account_id?: string |
| 235 | } | null { |
| 236 | try { |
| 237 | const parts = idToken.split(".") |
| 238 | if (parts.length !== 3) return null |
| 239 | const payloadB64 = parts[1] |
| 240 | let base64 = payloadB64.replace(/-/g, "+").replace(/_/g, "/") |
| 241 | while (base64.length % 4) { |
| 242 | base64 += "=" |
| 243 | } |
| 244 | const payloadBytes = Buffer.from(base64, "base64").toString("utf-8") |
| 245 | const payload = JSON.parse(payloadBytes) |
| 246 | const authClaims = payload["https://api.openai.com/auth"] |
| 247 | return { |
| 248 | email: payload.email, |
| 249 | chatgpt_plan_type: authClaims?.chatgpt_plan_type, |
| 250 | chatgpt_account_id: authClaims?.chatgpt_account_id, |
| 251 | } |
| 252 | } catch { |
| 253 | return null |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | async function loadCodexAuth(): Promise<Info | null> { |
| 258 | const authFile = await readJsonFile<CodexCliAuthFile>(path.join(resolveCodexHome(), "auth.json")) |