Versions in this module Expand all Collapse all v0 v0.4.0 Nov 27, 2026 v0.3.0 Nov 26, 2026 v0.2.0 Nov 23, 2026 v0.1.0 Nov 23, 2026 Changes in this version + const ActionLogin + const ActionLoginFailed + const ActionLogout + const ActionSetup + const ActionTokenCreate + const ActionTokenRevoke + const ActionUserAdd + const ActionUserDelete + const ActionUserPassword + const MinPasswordLen + const ReasonTooCommon + const ReasonTooLong + const ReasonTooShort + const ScopeAdmin + const SessionCookie + const ViaCLI + const ViaSession + const ViaToken + var ErrBadCredential = errors.New("auth: invalid name or password") + var ErrInvalid = errors.New("auth: invalid input") + var ErrLastUser = errors.New("auth: the last user cannot be deleted") + var ErrNameTaken = errors.New("auth: name already taken") + var ErrNotFound = errors.New("auth: not found") + var ErrSetupCode = errors.New("auth: invalid setup code") + var ErrSetupDone = errors.New("auth: setup already done") + var ErrUnauthorized = errors.New("auth: unauthorized") + func CheckPassword(pw string) error + func IsClientError(err error) bool + func WithClient(ctx context.Context, c Client) context.Context + func WithPrincipal(ctx context.Context, p Principal) context.Context + type AuditInfo struct + Action string + Actor string + At time.Time + Detail json.RawMessage + ID int64 + type Client struct + HTTPS bool + IP string + func ClientFrom(ctx context.Context) Client + type Deps struct + Clock util.Clock + Log zerolog.Logger + Rand io.Reader + Store storage.AuthStore + type Login struct + Expires time.Time + Token string + User UserInfo + type NewToken struct + Token string + type PasswordError struct + Reason string + func (e *PasswordError) Error() string + type Principal struct + Name string + TokenID string + UserID int64 + Via string + func CLI() Principal + func PrincipalFrom(ctx context.Context) (Principal, bool) + func (p Principal) Actor() string + type RateLimitError struct + RetryAfter time.Duration + func (e *RateLimitError) Error() string + type Service struct + func New(s Settings, d Deps) (*Service, error) + func (s *Service) AddUser(ctx context.Context, by Principal, name, pw, lang string) (UserInfo, error) + func (s *Service) Audit(ctx context.Context, from, to time.Time) ([]AuditInfo, error) + func (s *Service) Authenticate(ctx context.Context, token string) (Principal, error) + func (s *Service) AuthenticateToken(ctx context.Context, token string) (Principal, error) + func (s *Service) CreateToken(ctx context.Context, by Principal, name string, expires time.Duration) (NewToken, error) + func (s *Service) DeleteUser(ctx context.Context, by Principal, id int64) error + func (s *Service) Login(ctx context.Context, name, pw, ip string) (Login, error) + func (s *Service) Logout(ctx context.Context, p Principal) error + func (s *Service) RevokeToken(ctx context.Context, by Principal, id string) error + func (s *Service) SetPassword(ctx context.Context, by Principal, id int64, pw string) error + func (s *Service) Setup(ctx context.Context, r SetupRequest) (Login, error) + func (s *Service) SetupCode() string + func (s *Service) SetupRequired(ctx context.Context) (bool, error) + func (s *Service) Tokens(ctx context.Context) ([]TokenInfo, error) + func (s *Service) UserByName(ctx context.Context, name string) (UserInfo, error) + func (s *Service) Users(ctx context.Context) ([]UserInfo, error) + type Settings struct + SessionIdle time.Duration + SessionMax time.Duration + type SetupRequest struct + Code string + IP string + Lang string + Name string + Password string + type TokenInfo struct + CreatedAt time.Time + ExpiresAt *time.Time + ID string + LastUsed *time.Time + Name string + Scope string + type UserInfo struct + CreatedAt time.Time + ID int64 + Lang string + LastLogin *time.Time + Name string