Documentation
¶
Index ¶
Constants ¶
const ProviderOpenAICodex = "openai-codex"
ProviderOpenAICodex is the auth.json key under which ChatGPT/Codex subscription credentials are stored.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Credentials ¶
type Credentials struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresAt time.Time `json:"expires_at"`
AccountID string `json:"account_id"`
}
Credentials is a stored token set for one provider.
func LoginOpenAI ¶
func LoginOpenAI(ctx context.Context, opts LoginOptions) (Credentials, error)
LoginOpenAI runs the Codex device-code flow against auth.openai.com and returns the resulting credentials. It blocks until the browser approval is completed, ctx is cancelled, or the timeout elapses.
func RefreshOpenAI ¶
func RefreshOpenAI(ctx context.Context, httpc *http.Client, refreshToken string) (Credentials, error)
RefreshOpenAI exchanges a refresh token for a fresh credential set.
type LoginOptions ¶
type LoginOptions struct {
// OnDeviceCode is invoked once with the URL and code the user must enter in
// a browser to authorize.
OnDeviceCode func(verificationURL, userCode string)
// HTTPClient overrides the client used for token exchange (tests).
HTTPClient *http.Client
// Timeout bounds the wait for device-code approval (default 15 minutes).
Timeout time.Duration
}
LoginOptions configures the interactive OpenAI login flow.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists subscription credentials to a JSON file (default ~/.neo/auth.json), keyed by provider id. The file holds bearer/refresh tokens, so it is written with 0600 permissions. Each mutation does a read-modify-write with an atomic rename; there is no cross-process lock, which is sufficient for a single interactive CLI.
func DefaultStore ¶
DefaultStore returns the Store at ~/.neo/auth.json.
type TokenSource ¶
type TokenSource struct {
// contains filtered or unexported fields
}
TokenSource yields a valid OpenAI subscription access token, refreshing and persisting it through the Store when it nears expiry. It is safe for concurrent use.
func NewTokenSource ¶
func NewTokenSource(store *Store, key string) *TokenSource
NewTokenSource builds a TokenSource for the given provider key.
func (*TokenSource) Token ¶
func (ts *TokenSource) Token(ctx context.Context) (Credentials, error)
Token returns current, non-expired credentials, refreshing if needed. It returns an error if no credentials are stored (the user must log in).