Documentation
¶
Overview ¶
Package providerauth manages OAuth-backed provider accounts without exposing durable secrets to provider configuration or UI/API callers.
Index ¶
- Variables
- type Account
- type Binding
- type Credential
- type Endpoints
- type Flow
- type FlowState
- type Manager
- func (manager *Manager) Cancel(method Method, flowID string) error
- func (manager *Manager) Credential(ctx context.Context, binding Binding) (Credential, error)
- func (manager *Manager) Logout(_ context.Context, method Method) error
- func (manager *Manager) Models(ctx context.Context, binding Binding) ([]Model, error)
- func (manager *Manager) Poll(ctx context.Context, method Method, flowID string) (Flow, error)
- func (manager *Manager) Remove(_ context.Context, method Method, accountID string) error
- func (manager *Manager) SetDefault(_ context.Context, method Method, accountID string) error
- func (manager *Manager) Start(ctx context.Context, method Method) (Flow, error)
- func (manager *Manager) Status(_ context.Context, method Method) (Status, error)
- func (manager *Manager) ValidateBinding(_ context.Context, binding Binding) error
- type Method
- type Model
- type ModelKind
- type Options
- type Protocol
- type Service
- type Status
Constants ¶
This section is empty.
Variables ¶
var ( ErrUnsupportedMethod = errors.New("unsupported provider auth method") ErrUnsupportedGHES = errors.New("GitHub Enterprise Server is not supported") ErrFlowNotFound = errors.New("provider auth flow not found") ErrFlowExpired = errors.New("provider auth flow expired") ErrAuthorizationPending = errors.New("provider authorization pending") ErrAccessDenied = errors.New("provider authorization denied") ErrAccountNotFound = errors.New("provider auth account not found") ErrRequiresReauth = errors.New("provider auth account requires reauthentication") ErrNoCopilotSubscription = errors.New("GitHub account has no Copilot subscription") ErrInvalidBinding = errors.New("invalid provider auth binding") )
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct {
ID string `json:"id"`
Login string `json:"login"`
AuthenticatedAt time.Time `json:"authenticated_at"`
RequiresReauth bool `json:"requires_reauth"`
}
Account is the non-secret account projection exposed to clients.
type Binding ¶
type Binding struct {
Method Method `json:"method"`
AccountID string `json:"account_id,omitempty"`
}
Binding is the non-secret value stored on a Provider configuration.
type Credential ¶
type Credential struct {
Token string `json:"-"`
AccountID string `json:"account_id"`
BaseURL string `json:"base_url"`
Protocol Protocol `json:"protocol"`
Headers map[string]string `json:"headers,omitempty"`
}
Credential is resolved immediately before an upstream request. Token is intentionally excluded from JSON serialization to prevent accidental API or log exposure.
type Endpoints ¶
type Endpoints struct {
CodexDeviceStart string
CodexDevicePoll string
CodexToken string
CodexVerification string
CodexRuntime string
XAIDiscovery string
XAIRuntime string
CopilotDeviceStart string
CopilotOAuthToken string
CopilotUser string
CopilotToken string
CopilotUsage string
CopilotRuntime string
}
Endpoints contains managed upstream endpoints. The zero value selects the production endpoints. Non-zero overrides are intended only for hermetic tests and require AllowInsecureTestEndpoints when they are not trusted HTTPS origins.
type Flow ¶
type Flow struct {
ID string `json:"flow_id"`
Method Method `json:"method"`
State FlowState `json:"state"`
UserCode string `json:"user_code"`
VerificationURI string `json:"verification_uri"`
VerificationURIComplete string `json:"verification_uri_complete,omitempty"`
ExpiresAt time.Time `json:"expires_at"`
IntervalSeconds int `json:"interval_seconds,omitempty"`
Account *Account `json:"account,omitempty"`
Error string `json:"error,omitempty"`
}
Flow is the public device-flow projection. Upstream device tokens and PKCE material are deliberately absent and remain in process memory only.
type FlowState ¶
type FlowState string
FlowState is the public state of a device authorization flow.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager coordinates device flows, durable accounts, token refresh and runtime credential resolution for all managed login methods.
func NewManager ¶
NewManager creates an isolated manager with injectable dependencies.
func (*Manager) Credential ¶
Credential resolves a fresh runtime token and the immutable managed runtime profile for a Provider binding.
func (*Manager) Models ¶
Models returns the live, account-scoped model catalog for a managed login. Credentials are resolved immediately before the request and never included in the returned projection or an error body.
func (*Manager) SetDefault ¶
SetDefault selects the default usable account for a login method.
type Model ¶
type Model struct {
ID string `json:"id"`
Name string `json:"name,omitempty"`
Vendor string `json:"vendor,omitempty"`
Protocol Protocol `json:"protocol"`
Kind ModelKind `json:"kind"`
}
Model is a non-secret model projection returned by a managed provider's account-scoped catalog. Protocol is the wire format required by that model; Copilot may mix OpenAI Responses models with chat-completions models in one account catalog.
type ModelKind ¶
type ModelKind string
ModelKind separates inference catalogs that share /models but require different product surfaces and wire protocols.
type Options ¶
type Options struct {
ConfigDir string
HTTPClient *http.Client
Now func() time.Time
Rand io.Reader
Endpoints Endpoints
AllowInsecureTestEndpoints bool
}
Options supplies dependencies for Manager. ConfigDir is required. HTTPClient, Now and Rand are injectable to keep tests deterministic and offline.
type Protocol ¶
type Protocol string
Protocol is the wire protocol required by a managed provider runtime.
type Service ¶
type Service interface {
Start(context.Context, Method) (Flow, error)
Poll(context.Context, Method, string) (Flow, error)
Cancel(Method, string) error
Status(context.Context, Method) (Status, error)
SetDefault(context.Context, Method, string) error
Remove(context.Context, Method, string) error
Logout(context.Context, Method) error
ValidateBinding(context.Context, Binding) error
Credential(context.Context, Binding) (Credential, error)
Models(context.Context, Binding) ([]Model, error)
}
Service is the consuming-package-friendly contract implemented by Manager.