login

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package login is the supervisor's store of the owner's model logins (supervise.md, "The workspace runner"): the Claude token `factory-agent login claude` reads on stdin and the codex ChatGPT login `factory-agent login codex` imports from codex's auth.json. Each is a file under <statedir>/logins (0700), written 0600 through a temp file and a rename. The gateway reads the claude login on every request, so a re-import applies to the next one. The codex login is the gateway's chatgpt.Refresher's Store (ChatGPT): it refreshes the tokens and writes them back here.

No value here is ever logged or printed: Codex's String, Format, LogValue and MarshalJSON redact, and every error names the file or the field, never its content.

Index

Constants

View Source
const (
	ClaudeFile = "claude.json"
	CodexFile  = "codex.json"
)

The store's files.

View Source
const Dir = "logins"

Dir is the store's directory under the state dir.

Variables

View Source
var ErrNoLogin = errors.New("no login")

ErrNoLogin is a login that was never stored.

Functions

func ClaudeToken

func ClaudeToken(text string) (string, error)

ClaudeToken is the one OAuth token in text: what `claude setup-token` printed around it (prose, a URL, terminal escapes), as pasted. A token repeated is one; none, or two different ones, is an error that names neither.

Types

type ChatGPT

type ChatGPT struct{ Store Store }

ChatGPT is the codex login as the gateway's chatgpt.Refresher loads and saves it.

func (ChatGPT) Load

Load is the stored codex login.

func (ChatGPT) Save

func (s ChatGPT) Save(_ context.Context, l chatgpt.Login) error

Save writes l's tokens and last refresh into the stored codex login, keeping its account and its provenance.

type Codex

type Codex struct {
	AccessToken, RefreshToken   string
	AccountID, UserID, PlanType string
	Issuer, ClientID            string
	LastRefresh                 time.Time
}

Codex is the owner's codex ChatGPT login: the tokens, the account identifiers the run bundle carries (runbundle.CodexAccount), codex's tokens.oauth_provenance (Issuer and ClientID, both or neither) and its last_refresh. It never prints its values.

func ParseCodexAuth

func ParseCodexAuth(b []byte) (Codex, error)

ParseCodexAuth reads codex's auth.json (a ChatGPT login): the tokens, the account identifiers from the id_token's claims (its signature isn't checked: the file is the owner's own), tokens.oauth_provenance when it has one (codex main writes it; rust-v0.163.0 doesn't) and last_refresh. tokens.account_id, when set, must match the claim's.

func (Codex) Format

func (c Codex) Format(f fmt.State, _ rune)

Format redacts every verb.

func (Codex) GoString

func (c Codex) GoString() string

GoString redacts.

func (Codex) LogValue

func (c Codex) LogValue() slog.Value

LogValue redacts.

func (Codex) MarshalJSON

func (c Codex) MarshalJSON() ([]byte, error)

MarshalJSON redacts.

func (Codex) String

func (Codex) String() string

type Store

type Store struct{ Path string }

Store is the login store at Path (<statedir>/logins).

func ForStateDir

func ForStateDir(stateDir string) Store

ForStateDir is the store under stateDir.

func (Store) Claude

func (s Store) Claude() (string, error)

Claude is the stored Claude OAuth token; ErrNoLogin when there is none.

func (Store) Codex

func (s Store) Codex() (Codex, error)

Codex is the stored codex login; ErrNoLogin when there is none.

func (Store) SaveClaude

func (s Store) SaveClaude(token string) error

SaveClaude stores token, the one ClaudeToken found in `claude setup-token`'s output: one line, surrounding white space trimmed.

func (Store) SaveCodex

func (s Store) SaveCodex(c Codex) error

SaveCodex stores c; it needs the access token and the three identifiers.

Jump to

Keyboard shortcuts

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