(
authPathOrOptions: string | { authPath?: string; env?: NodeJS.ProcessEnv } = {},
)
| 60 | } |
| 61 | |
| 62 | export function readCodexAuthState( |
| 63 | authPathOrOptions: string | { authPath?: string; env?: NodeJS.ProcessEnv } = {}, |
| 64 | ): CodexAuthState | null { |
| 65 | const authPath = resolveRequestedAuthPath(authPathOrOptions); |
| 66 | const raw = readJsonObject(authPath); |
| 67 | if (!raw) { |
| 68 | return null; |
| 69 | } |
| 70 | const tokens = readCodexAuthTokens(raw); |
| 71 | const tokenIdentity = extractCodexTokenIdentity({ |
| 72 | accessToken: tokens.accessToken, |
| 73 | idToken: tokens.idToken, |
| 74 | accountId: tokens.accountId, |
| 75 | authMode: firstString(raw.auth_mode), |
| 76 | }); |
| 77 | const identity = buildCodexAuthIdentity(raw, tokenIdentity, authPath); |
| 78 | return { |
| 79 | authPath, |
| 80 | raw, |
| 81 | tokens, |
| 82 | identity, |
| 83 | }; |
| 84 | } |
| 85 | |
| 86 | export function readCodexAccountIdentity( |
| 87 | authPathOrOptions: string | { authPath?: string; env?: NodeJS.ProcessEnv } = {}, |
no test coverage detected