codexauth

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package codexauth reads and writes the Codex CLI's own sign-in, $CODEX_HOME/auth.json, so an account can be handed to Codex.

Index

Constants

View Source
const HomeEnvVar = "CODEX_HOME"

HomeEnvVar overrides Codex's home directory, as it does for Codex.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	Mode        string // auth_mode; empty in older files
	HasAPIKey   bool   // OPENAI_API_KEY is set
	Tokens      *auth.Tokens
	AccountID   string // tokens.account_id
	LastRefresh time.Time
	// contains filtered or unexported fields
}

Auth is the sign-in stored in auth.json.

func (*Auth) IsChatGPT

func (a *Auth) IsChatGPT() bool

IsChatGPT reports whether this is a ChatGPT sign-in, using Codex's rules: an explicit auth_mode wins, otherwise an API key means API-key mode.

type Home

type Home struct {
	Dir string
}

Home is a Codex home directory (default ~/.codex).

func DefaultHome

func DefaultHome(getenv func(string) string) (Home, error)

DefaultHome returns $CODEX_HOME, or ~/.codex.

func (Home) AuthPath

func (h Home) AuthPath() string

AuthPath is where Codex keeps its sign-in.

func (Home) Backup

func (h Home) Backup(dst string) error

Backup copies auth.json to dst, readable only by the owner.

func (Home) Read

func (h Home) Read() (*Auth, error)

Read loads auth.json. It returns nil, nil if Codex isn't signed in.

func (Home) SignIn

func (h Home) SignIn(tokens auth.Tokens, accountID string, lastRefresh time.Time) error

SignIn replaces auth.json with a ChatGPT sign-in, in the format `codex login` writes.

func (Home) StoreMode

func (h Home) StoreMode() (string, error)

StoreMode returns Codex's cli_auth_credentials_store setting from config.toml: "file" (the default), "keyring", "auto" or "ephemeral". Only top-level keys are read; this is not a full TOML parser.

func (Home) UpdateTokens

func (h Home) UpdateTokens(prev *Auth, tokens auth.Tokens, lastRefresh time.Time) error

UpdateTokens swaps new tokens into prev, keeping every other field.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL