Help us shape the future of Go! Take the 2026 Go Developer Survey

auth

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKeyAuth

type APIKeyAuth interface {
	Name() string
	Resolve(context.Context, AuthContext, *Credential) (*AuthResult, error)
}

type APIKeyCheck

type APIKeyCheck interface {
	Check(context.Context, AuthContext, *Credential) (*AuthCheck, error)
}

type APIKeyLogin

type APIKeyLogin interface {
	Login(context.Context, AuthInteraction) (*Credential, error)
}

type AuthCheck

type AuthCheck struct {
	Source string         `json:"source,omitempty"`
	Type   CredentialType `json:"type"`
}

type AuthContext

type AuthContext interface {
	Env(context.Context, string) (string, bool)
	FileExists(context.Context, string) bool
}

type AuthEvent

type AuthEvent struct {
	Type             AuthEventType
	Message          string
	Links            []AuthInfoLink
	URL              string
	Instructions     string
	UserCode         string
	VerificationURI  string
	IntervalSeconds  int
	ExpiresInSeconds int
}

type AuthEventType

type AuthEventType string
const (
	EventInfo       AuthEventType = "info"
	EventAuthURL    AuthEventType = "auth_url"
	EventDeviceCode AuthEventType = "device_code"
	EventProgress   AuthEventType = "progress"
)
type AuthInfoLink struct {
	URL   string
	Label string
}

type AuthInteraction

type AuthInteraction interface {
	Prompt(context.Context, AuthPrompt) (string, error)
	Notify(AuthEvent)
}

type AuthPrompt

type AuthPrompt struct {
	Type        PromptType
	Message     string
	Placeholder string
	Options     []PromptOption
}

type AuthResult

type AuthResult struct {
	Auth   ModelAuth         `json:"auth"`
	Env    map[string]string `json:"env,omitempty"`
	Source string            `json:"source,omitempty"`
}

func ResolveProviderAuth

func ResolveProviderAuth(
	ctx context.Context,
	providerID string,
	methods ProviderAuth,
	credentials CredentialStore,
	authContext AuthContext,
	overrides *ResolutionOverrides,
) (*AuthResult, error)

type AuthType

type AuthType string
const (
	AuthTypeAPIKey AuthType = "api_key"
	AuthTypeOAuth  AuthType = "oauth"
)

type Credential

type Credential struct {
	Type    CredentialType
	Key     *string
	Env     map[string]string
	Refresh string
	Access  string
	Expires int64
	Extra   map[string]json.RawMessage
	// contains filtered or unexported fields
}

Credential retains unknown fields because auth.json is shared with TS pi and later provider OAuth flows attach provider-specific token metadata.

func APIKeyCredential

func APIKeyCredential(key string) *Credential

func APIKeyEnvCredential

func APIKeyEnvCredential(env map[string]string, envOrder ...string) *Credential

func OAuthCredential

func OAuthCredential(refresh, access string, expires int64) *Credential

func OAuthCredentialAccessFirst

func OAuthCredentialAccessFirst(access, refresh string, expires int64) *Credential

OAuthCredentialAccessFirst preserves the property insertion order used by providers whose upstream credential literals place access before refresh.

func (*Credential) Clone

func (credential *Credential) Clone() *Credential

func (Credential) MarshalJSON

func (credential Credential) MarshalJSON() ([]byte, error)

func (*Credential) SetExtra

func (credential *Credential) SetExtra(name string, value json.RawMessage)

func (*Credential) UnmarshalJSON

func (credential *Credential) UnmarshalJSON(data []byte) error

type CredentialInfo

type CredentialInfo struct {
	ProviderID string
	Type       CredentialType
}

type CredentialStore

type CredentialStore interface {
	Read(context.Context, string) (*Credential, error)
	List(context.Context) ([]CredentialInfo, error)
	Modify(context.Context, string, ModifyFunc) (*Credential, error)
	Delete(context.Context, string) error
}

CredentialStore is the upstream seam that lets applications own persistence.

func BindCredentialStore added in v0.7.1

func BindCredentialStore(ctx context.Context, store CredentialStore, provider string) (CredentialStore, error)

BindCredentialStore freezes a selectable store for one provider resolution. Ordinary stores pass through unchanged.

type CredentialType

type CredentialType string
const (
	CredentialAPIKey CredentialType = "api_key"
	CredentialOAuth  CredentialType = "oauth"
)

type EnvAPIKeyAuth

type EnvAPIKeyAuth struct {
	DisplayName string
	EnvVars     []string
}

func (EnvAPIKeyAuth) Login

func (method EnvAPIKeyAuth) Login(ctx context.Context, interaction AuthInteraction) (*Credential, error)

func (EnvAPIKeyAuth) Name

func (method EnvAPIKeyAuth) Name() string

func (EnvAPIKeyAuth) Resolve

func (method EnvAPIKeyAuth) Resolve(
	ctx context.Context,
	authContext AuthContext,
	credential *Credential,
) (*AuthResult, error)

type EnvironmentContext

type EnvironmentContext struct{}

func (EnvironmentContext) Env

func (EnvironmentContext) FileExists

func (EnvironmentContext) FileExists(_ context.Context, path string) bool

type Error

type Error struct {
	Code    ErrorCode
	Message string
	Cause   error
}

func (*Error) Error

func (authError *Error) Error() string

Error keeps the underlying cause in the surfaced message (upstream 4cf0a729): callers surface the message only, so a bare wrapper such as "OAuth refresh failed for openai-codex" would hide the provider response.

func (*Error) Unwrap

func (authError *Error) Unwrap() error

type ErrorCode

type ErrorCode string
const (
	ErrorModelSource     ErrorCode = "model_source"
	ErrorModelValidation ErrorCode = "model_validation"
	ErrorProvider        ErrorCode = "provider"
	ErrorStream          ErrorCode = "stream"
	ErrorAuth            ErrorCode = "auth"
	ErrorOAuth           ErrorCode = "oauth"
)

type MemoryStore

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

func NewMemoryStore

func NewMemoryStore(initial map[string]*Credential) *MemoryStore

func (*MemoryStore) Delete

func (store *MemoryStore) Delete(_ context.Context, provider string) error

func (*MemoryStore) List

func (store *MemoryStore) List(_ context.Context) ([]CredentialInfo, error)

func (*MemoryStore) Modify

func (store *MemoryStore) Modify(_ context.Context, provider string, modify ModifyFunc) (*Credential, error)

func (*MemoryStore) Read

func (store *MemoryStore) Read(_ context.Context, provider string) (*Credential, error)

type ModelAuth

type ModelAuth struct {
	APIKey  *string            `json:"apiKey,omitempty"`
	Headers map[string]*string `json:"headers,omitempty"`
	BaseURL *string            `json:"baseUrl,omitempty"`
}

type ModifyFunc

type ModifyFunc func(current *Credential) (*Credential, error)

type OAuth

type OAuth interface {
	Name() string
	Login(context.Context, AuthInteraction) (*Credential, error)
	Refresh(context.Context, *Credential) (*Credential, error)
	ToAuth(*Credential) (ModelAuth, error)
}

type OAuthLoginLabel

type OAuthLoginLabel interface {
	LoginLabel() string
}

type PromptOption

type PromptOption struct {
	ID          string
	Label       string
	Description string
}

type PromptType

type PromptType string
const (
	PromptText       PromptType = "text"
	PromptSecret     PromptType = "secret"
	PromptSelect     PromptType = "select"
	PromptManualCode PromptType = "manual_code"
)

type ProviderAuth

type ProviderAuth struct {
	APIKey APIKeyAuth
	OAuth  OAuth
}

type ResolutionOverrides

type ResolutionOverrides struct {
	APIKey           *string
	Env              map[string]string
	MinOAuthValidity *time.Duration
}

Directories

Path Synopsis
Package accounts adds named credentials without changing the provider-keyed compatibility store.
Package accounts adds named credentials without changing the provider-keyed compatibility store.

Jump to

Keyboard shortcuts

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