Documentation
¶
Overview ¶
Package auth provides authentication and pairing for Hub connections.
Index ¶
- Constants
- Variables
- type AuthorizedHub
- type ConfigStorageAdapter
- func (s *ConfigStorageAdapter) AddAuthorizedHub(hub AuthorizedHub) error
- func (s *ConfigStorageAdapter) GetAuthorizedHubs() []AuthorizedHub
- func (s *ConfigStorageAdapter) RemoveAuthorizedHub(hubID string) error
- func (s *ConfigStorageAdapter) Save() error
- func (s *ConfigStorageAdapter) UpdateHubLastSeen(hubID string, lastSeen time.Time) error
- type Manager
- func (m *Manager) CancelPendingPairing()
- func (m *Manager) GenerateCode(hubID, hubName, hubPlatform string) (string, error)
- func (m *Manager) GetAuthorizedHubs() []AuthorizedHub
- func (m *Manager) GetPendingPairing() *PairingSession
- func (m *Manager) IsHubAuthorized(hubID string) bool
- func (m *Manager) RevokeHub(hubID string) error
- func (m *Manager) SetPairingCodeCallback(cb func(code string, expiresIn time.Duration))
- func (m *Manager) ValidateCode(hubID, hubName, code string) (string, error)
- func (m *Manager) ValidateToken(hubID, token string) bool
- type PairingSession
- type Storage
Constants ¶
const ( // CodeLength is the number of digits in a pairing code. CodeLength = 6 // CodeExpiry is how long a pairing code is valid. CodeExpiry = 60 * time.Second // TokenLength is the number of random bytes for tokens. TokenLength = 32 // MaxFailedAttempts before rate limiting. MaxFailedAttempts = 3 // RateLimitDuration after max failed attempts. RateLimitDuration = 5 * time.Minute )
Variables ¶
var ( ErrCodeExpired = errors.New("pairing code expired") ErrCodeInvalid = errors.New("invalid pairing code") ErrRateLimited = errors.New("too many failed attempts, try again later") ErrHubNotFound = errors.New("hub not found") ErrTokenInvalid = errors.New("invalid token") ErrNoPendingPairing = errors.New("no pending pairing") )
Errors returned by auth operations.
Functions ¶
This section is empty.
Types ¶
type AuthorizedHub ¶
type AuthorizedHub struct {
ID string `json:"id"`
Name string `json:"name"`
Platform string `json:"platform,omitempty"`
Token string `json:"token"`
PairedAt time.Time `json:"pairedAt"`
LastSeen time.Time `json:"lastSeen"`
}
AuthorizedHub represents a Hub that has been paired with this Agent.
type ConfigStorageAdapter ¶
type ConfigStorageAdapter struct {
// contains filtered or unexported fields
}
ConfigStorageAdapter adapts config.Manager to implement auth.Storage.
func NewConfigStorage ¶
func NewConfigStorage(cfg *config.Manager) *ConfigStorageAdapter
NewConfigStorage creates a new storage adapter from a config manager.
func (*ConfigStorageAdapter) AddAuthorizedHub ¶
func (s *ConfigStorageAdapter) AddAuthorizedHub(hub AuthorizedHub) error
AddAuthorizedHub adds a Hub to the authorized list.
func (*ConfigStorageAdapter) GetAuthorizedHubs ¶
func (s *ConfigStorageAdapter) GetAuthorizedHubs() []AuthorizedHub
GetAuthorizedHubs returns the list of authorized Hubs.
func (*ConfigStorageAdapter) RemoveAuthorizedHub ¶
func (s *ConfigStorageAdapter) RemoveAuthorizedHub(hubID string) error
RemoveAuthorizedHub removes a Hub from the authorized list.
func (*ConfigStorageAdapter) Save ¶
func (s *ConfigStorageAdapter) Save() error
Save persists the storage (no-op, config saves on each change).
func (*ConfigStorageAdapter) UpdateHubLastSeen ¶
func (s *ConfigStorageAdapter) UpdateHubLastSeen(hubID string, lastSeen time.Time) error
UpdateHubLastSeen updates the LastSeen timestamp for a Hub.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles authentication and pairing operations.
func (*Manager) CancelPendingPairing ¶
func (m *Manager) CancelPendingPairing()
CancelPendingPairing cancels any pending pairing session.
func (*Manager) GenerateCode ¶
GenerateCode creates a new 6-digit pairing code for a Hub.
func (*Manager) GetAuthorizedHubs ¶
func (m *Manager) GetAuthorizedHubs() []AuthorizedHub
GetAuthorizedHubs returns the list of authorized Hubs.
func (*Manager) GetPendingPairing ¶
func (m *Manager) GetPendingPairing() *PairingSession
GetPendingPairing returns the current pending pairing session, if any.
func (*Manager) IsHubAuthorized ¶
IsHubAuthorized checks if a Hub is in the authorized list (by ID only).
func (*Manager) SetPairingCodeCallback ¶
SetPairingCodeCallback sets the callback for when a pairing code is generated.
func (*Manager) ValidateCode ¶
ValidateCode checks if the provided code matches the pending pairing. Returns the generated token on success.
func (*Manager) ValidateToken ¶
ValidateToken checks if a Hub's token is valid.