openaiauth

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 14 Imported by: 3

Documentation

Overview

Package openaiauth implements renewable ChatGPT subscription OAuth credentials. It deliberately delegates persistence and login presentation to the host application.

Index

Constants

View Source
const (
	DefaultIssuerURL = "https://auth.openai.com"
	// DefaultClientID is the public client identifier used by the OpenAI Codex
	// device and browser authorization flows. Hosts may override it in Config.
	DefaultClientID = "app_EMoamEEZ73f0CkXaXp7hrann"
	DefaultScope    = "openid profile email offline_access api.connectors.read api.connectors.invoke"
)
View Source
const Provider = "openai_subscription"

Variables

This section is empty.

Functions

func ExchangeAuthorizationCode

func ExchangeAuthorizationCode(ctx context.Context, config Config, authorizationCode, codeVerifier, redirectURI string) (tokenResponse, error)

Types

type AuthorizationRequest

type AuthorizationRequest struct {
	URL          string
	State        string
	CodeVerifier string
	RedirectURI  string
}

func NewAuthorizationRequest

func NewAuthorizationRequest(config Config, redirectURI string) (AuthorizationRequest, error)

type Config

type Config struct {
	IssuerURL         string
	ClientID          string
	Originator        string
	HTTPClient        *http.Client
	Now               func() time.Time
	RefreshBefore     time.Duration
	DevicePollTimeout time.Duration
}

type DeviceCode

type DeviceCode struct {
	VerificationURL string
	UserCode        string
	DeviceAuthID    string
	Interval        time.Duration
}

func RequestDeviceCode

func RequestDeviceCode(ctx context.Context, config Config) (DeviceCode, error)

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager serializes refresh and logout for one credential profile. Hosts should reuse a manager per profile and coordinate refreshes separately if credentials are shared across processes.

func NewManager

func NewManager(profile string, store llmauth.Store, config Config) (*Manager, error)

func (*Manager) Apply

func (m *Manager) Apply(ctx context.Context, request *http.Request) error

func (*Manager) CompleteAuthorization

func (m *Manager) CompleteAuthorization(ctx context.Context, code, verifier, redirectURI string) (llmauth.Credential, error)

CompleteAuthorization exchanges a browser callback code. The host must first verify that the callback state matches AuthorizationRequest.State.

func (*Manager) LoginDevice

func (m *Manager) LoginDevice(ctx context.Context, onCode func(DeviceCode)) (llmauth.Credential, error)

func (*Manager) Logout

func (m *Manager) Logout(ctx context.Context) error

func (*Manager) RecoverUnauthorized

func (m *Manager) RecoverUnauthorized(ctx context.Context) error

func (*Manager) Status

func (m *Manager) Status(ctx context.Context) (llmauth.Credential, error)

Jump to

Keyboard shortcuts

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