Documentation
¶
Overview ¶
Package auth provides auth service
Package auth provides authentication providers ¶
Package auth provides authentication services with pluggable storage
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthConfig ¶
type AuthConfig struct {
BaseURL string
Username string
Password string
PresetToken string
Client *http.Client
ClientID string
ClientUUID string
Version string
Timeout time.Duration
}
AuthConfig configures the username/password provider
type AuthProvider ¶
type AuthProvider struct {
// contains filtered or unexported fields
}
AuthProvider implements TokenProvider using username/password authentication
func NewAuthProvider ¶
func NewAuthProvider(config AuthConfig) *AuthProvider
NewAuthProvider creates a new username/password token provider
func (*AuthProvider) FetchToken ¶
FetchToken implements TokenProvider
func (*AuthProvider) SetPresetToken ¶
func (p *AuthProvider) SetPresetToken(token string)
SetPresetToken sets a token to use on the next FetchToken call Useful for scenarios where you have a valid token but need to initialize the provider
func (*AuthProvider) Type ¶
func (p *AuthProvider) Type() string
Type implements TokenProvider for AuthProvider
func (*AuthProvider) UpdateCredentials ¶
func (p *AuthProvider) UpdateCredentials(username, password string)
UpdateCredentials updates the username and password
type Config ¶
type Config struct {
RefreshBuffer time.Duration
Storage TokenStorage // If nil, uses MemoryStorage
}
Config configures the auth manager
type FileStorage ¶
type FileStorage struct {
// contains filtered or unexported fields
}
FileStorage implements file-based token storage
func NewFileStorage ¶
func NewFileStorage(filePath string) (*FileStorage, error)
NewFileStorage creates a new file-based token storage
func (*FileStorage) Retrieve ¶
func (s *FileStorage) Retrieve() (string, time.Time, error)
Retrieve implements TokenStorage
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles authentication token lifecycle
func NewManager ¶
func NewManager(provider TokenProvider, config Config) *Manager
NewManager creates a new authentication manager
func (*Manager) GetToken ¶
GetToken returns a valid authentication token. if the current token is expired or about to expire, it will automatically refresh
func (*Manager) HasValidToken ¶
HasValidToken returns true if the manager has a valid token
func (*Manager) InvalidateToken ¶
func (m *Manager) InvalidateToken()
InvalidateToken marks the current token as invalid (e.g. 401)
func (*Manager) TokenExpiry ¶
TokenExpiry returns the current token's expiry time
type MemoryStorage ¶
type MemoryStorage struct {
// contains filtered or unexported fields
}
MemoryStorage implements in-memory token storage (default)
func NewMemoryStorage ¶
func NewMemoryStorage() *MemoryStorage
NewMemoryStorage creates a new in-memory token storage
func (*MemoryStorage) Retrieve ¶
func (s *MemoryStorage) Retrieve() (string, time.Time, error)
Retrieve implements TokenStorage
type StaticTokenProvider ¶ added in v0.2.1
type StaticTokenProvider struct {
// contains filtered or unexported fields
}
StaticTokenProvider returns the same bearer token for every request.
This is intended for token-only configurations where the token is managed outside of gocmlclient (e.g. Terraform provider config). It never attempts to authenticate via username/password.
func NewStaticTokenProvider ¶ added in v0.2.1
func NewStaticTokenProvider(token string) *StaticTokenProvider
NewStaticTokenProvider returns a TokenProvider that always yields the given token.
func (*StaticTokenProvider) FetchToken ¶ added in v0.2.1
FetchToken implements TokenProvider.
func (*StaticTokenProvider) Type ¶ added in v0.2.1
func (p *StaticTokenProvider) Type() string
Type implements TokenProvider.
type Stats ¶
type Stats struct {
HasToken bool
TokenExpiry time.Time
IsValid bool
TimeUntilRefresh time.Duration
StorageType string
}
Stats contains authentication manager statistics
type TokenProvider ¶
type TokenProvider interface {
// FetchToken retrieves a new authentication token
FetchToken(ctx context.Context) (token string, expiry time.Time, err error)
// Type returns the provider type identifier
Type() string
}
TokenProvider defines the interface for token acquisition
type TokenStorage ¶
type TokenStorage interface {
// Store saves a token with its expiry time
Store(token string, expiry time.Time) error
// Retrieve gets the stored token and expiry time
Retrieve() (token string, expiry time.Time, err error)
// Clear removes the stored token
Clear() error
// Type returns the storage type identifier
Type() string
}
TokenStorage defines the interface for token storage backends
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport wraps an HTTP RoundTripper to automatically add authentication
func NewTransport ¶
func NewTransport(base http.RoundTripper, manager *Manager, skip []string) *Transport
NewTransport creates a new authenticated transport