Versions in this module Expand all Collapse all v0 v0.1.0 Nov 9, 2026 Changes in this version + const APIKeyPrefix + const DefaultSessionTTL + const RoleAdmin + const RoleUser + const ScopeAdmin + const ScopeMetricsRead + const ScopeRead + const ScopeWrite + var DefaultArgon2 = Argon2Params + var ErrDisabled = errors.New("auth: account disabled") + var ErrExpiryInPast = errors.New("auth: expiry is in the past") + var ErrInvalidAPIKey = errors.New("auth: invalid or expired API key") + var ErrInvalidCredentials = errors.New("auth: invalid username or password") + var ErrNotFound = errors.New("auth: not found") + var ErrScopeNotAllowed = errors.New("auth: scope not allowed for this account") + var KnownScopes = []string + func HashInviteToken(token string) []byte + func NewInviteToken() (token string, hash []byte) + func RoleScopes(role string) []string + func WithPrincipal(ctx context.Context, p *Principal) context.Context + type Argon2Params struct + Iterations uint32 + MemoryKiB uint32 + Parallelism uint8 + type ClientInfo struct + IP string + UserAgent string + type FailureLimiter struct + func NewFailureLimiter(max int, window time.Duration) *FailureLimiter + func (l *FailureLimiter) Blocked(key string) (bool, time.Duration) + func (l *FailureLimiter) Fail(key string) + func (l *FailureLimiter) Reset(key string) + type Hasher struct + func NewHasher(p Argon2Params, concurrency int) *Hasher + func (h *Hasher) Hash(ctx context.Context, password string) (string, error) + func (h *Hasher) Verify(ctx context.Context, password, encoded string) (ok, rehash bool, err error) + func (h *Hasher) VerifyDummy(ctx context.Context, password string) + type Method string + const MethodAPIKey + const MethodSession + type NewSession struct + CSRFToken string + Session db.Session + Token string + type Principal struct + APIKeyID uuid.UUID + CSRFToken string + Method Method + Scopes []string + SessionID uuid.UUID + User db.User + func FromContext(ctx context.Context) *Principal + func (p *Principal) CheckCSRF(token string) bool + func (p *Principal) HasScope(scope string) bool + func (p *Principal) IsAdmin() bool + type RateLimitedError struct + RetryAfter time.Duration + func (e *RateLimitedError) Error() string + type Service struct + func NewService(st *store.Store, hasher *Hasher, log *slog.Logger) *Service + func (s *Service) AuthenticateAPIKey(ctx context.Context, key string) (*Principal, error) + func (s *Service) AuthenticateSession(ctx context.Context, token string) (*Principal, error) + func (s *Service) ChangePassword(ctx context.Context, p *Principal, current, next string) error + func (s *Service) CleanExpired(ctx context.Context) (int64, error) + func (s *Service) CreateAPIKey(ctx context.Context, u db.User, name string, scopes []string, ...) (db.ApiKey, string, error) + func (s *Service) DeleteAPIKey(ctx context.Context, userID, id uuid.UUID) error + func (s *Service) DeleteSession(ctx context.Context, userID, id uuid.UUID) error + func (s *Service) Hasher() *Hasher + func (s *Service) ListAPIKeys(ctx context.Context, userID uuid.UUID) ([]db.ApiKey, error) + func (s *Service) ListSessions(ctx context.Context, userID uuid.UUID) ([]db.Session, error) + func (s *Service) Login(ctx context.Context, username, password string, ci ClientInfo) (db.User, NewSession, error) + func (s *Service) Logout(ctx context.Context, p *Principal) error + func (s *Service) SessionTTL() time.Duration + func (s *Service) StartSession(ctx context.Context, q *db.Queries, u db.User, ci ClientInfo) (NewSession, error)