Documentation
¶
Overview ¶
Package chatgpt is the codex ChatGPT login the gateway sends to chatgpt.com, and its Refresher (gateway.md, "ChatGPT refresh"). One Refresher per supervisor, shared by its gateways, refreshes the access token when its exp is less than 5 minutes away and after an upstream 401, one refresh at a time, and writes the new tokens back to the Store before they are used. The VM never refreshes: its auth.json has placeholders.
The endpoint, the client id, the request and the failure classes are codex's at rust-v0.163.0, the version provision/base.sh pins: codex-rs/login/src/auth/manager.rs (REFRESH_TOKEN_URL, CLIENT_ID, request_chatgpt_token_refresh, classify_refresh_token_failure, RefreshResponse, the 5-minute window and the 8-day interval) and codex-rs/login/src/oauth/client.rs (OAuthClient::refresh, TokenEncoding::Json), with the error code read as codex-rs/login/src/oauth/error.rs reads it. They are unverified against the live service until the owner's smoke run.
No token is ever logged, printed or put in an error: Login redacts, and errors carry the status and an error code from the known list only.
Index ¶
Constants ¶
const ( TokenURL = "https://auth.openai.com/oauth/token" ClientID = "app_EMoamEEZ73f0CkXaXp7hrann" )
The refresh endpoint and client id of a login without provenance (codex rust-v0.163.0's REFRESH_TOKEN_URL and CLIENT_ID).
Variables ¶
var ErrNoRefreshToken = errors.New("chatgpt: the login has no refresh token: factory-agent login codex again")
ErrNoRefreshToken is a login without a refresh token (or with the VM's placeholder): never sent.
var ErrPermanent = errors.New("chatgpt: the auth server refused the refresh token: log codex in again, then factory-agent login codex")
ErrPermanent is wrapped by a refresh the auth server refused for good (codex's RefreshTokenError::Permanent): the refresher stops trying until the stored login changes.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Store is required.
Store Store
// Client sends the refresh; default 30 s, the system roots and no proxy.
Client *http.Client
// TokenURL is the endpoint of a login without provenance; default TokenURL (tests).
TokenURL string
// Clock defaults to the real clock; Logger to discarding.
Clock clock.Clock
Logger *slog.Logger
}
Config configures a Refresher.
type Login ¶
type Login struct {
AccessToken, RefreshToken string
AccountID string
Issuer, ClientID string
LastRefresh time.Time
}
Login is the owner's codex ChatGPT login. Issuer and ClientID are codex's tokens.oauth_provenance, when auth.json has it (codex main records it; rust-v0.163.0 doesn't): a refresh then goes to <Issuer>/oauth/token with ClientID. String, Format, GoString, LogValue, MarshalJSON and MarshalText redact.
func (Login) MarshalJSON ¶
MarshalJSON is the redacted form as a JSON string.
func (Login) MarshalText ¶
MarshalText is the redacted form.
type Refresher ¶
type Refresher struct {
// contains filtered or unexported fields
}
Refresher holds the cached login and refreshes it, one refresh at a time.
func (*Refresher) Current ¶
Current returns the cached login, refreshed first when it's due: its access token's exp is less than 5 minutes away, or, without a readable exp, it was last refreshed more than 8 days ago. A failed refresh returns the cached login with the error, so the request still goes out with it. Only a login that can't be loaded returns no token.
func (*Refresher) Unauthorized ¶
Unauthorized follows an upstream 401 for the access token used: when the cached token is no longer used, another caller has refreshed it already and it is returned; when the login was refreshed less than minUnauthorizedRefresh ago, the cached login is returned unrefreshed (the gateway then passes the 401 on); otherwise it refreshes.