Versions in this module Expand all Collapse all v0 v0.3.0 Aug 26, 2026 Changes in this version + var ErrAccountLocked = errors.New("authit/user: account locked") + var ErrEmailNotVerified = errors.New("authit/user: email not verified") + var ErrEmailTaken = errors.New("authit/user: email already registered") + var ErrInvalidCredentials = errors.New("authit/user: invalid credentials") + var ErrInvalidToken = errors.New("authit/user: invalid or expired token") + var ErrInvalidTwoFactor = errors.New("authit/user: invalid two-factor code") + var ErrSessionNotFound = errors.New("authit/user: session not found") + var ErrTwoFactorEnabled = errors.New("authit/user: two-factor already enabled") + var ErrTwoFactorNotEnabled = errors.New("authit/user: two-factor not enabled") + var ErrTwoFactorRequired = errors.New("authit/user: two-factor code required") + type AuthResult struct + PendingTwoFactorToken string + RequiresTwoFactor bool + Tokens *TokenPair + User store.User + type Config struct + AccessTokenTTL time.Duration + AuditLogger audit.Logger + BackupCodeCount int + EmailVerification EmailVerificationPolicy + EmailVerificationTTL time.Duration + FailedLoginWindow time.Duration + MaxFailedLoginAttempts int + PasswordResetTTL time.Duration + PendingTwoFactorTTL time.Duration + RefreshTokenTTL time.Duration + TOTPEncryptionKey []byte + TOTPIssuer string + type EmailSender interface + SendEmailVerification func(ctx context.Context, email, token string) error + SendPasswordReset func(ctx context.Context, email, token string) error + type EmailVerificationPolicy int + const EmailVerificationOptional + const EmailVerificationRequired + type NoopEmailSender struct + func (NoopEmailSender) SendEmailVerification(ctx context.Context, email, token string) error + func (NoopEmailSender) SendPasswordReset(ctx context.Context, email, token string) error + type Service struct + func NewService(stores Stores, signer authitjwt.Signer, emailer EmailSender, cfg Config) (*Service, error) + func (s *Service) Authenticate(ctx context.Context, email, password, userAgent, ipAddress string) (AuthResult, error) + func (s *Service) BeginTwoFactorSetup(ctx context.Context, userID, accountEmail string) (TwoFactorSetup, error) + func (s *Service) ChangePassword(ctx context.Context, userID, currentPassword, newPassword string) error + func (s *Service) ConfirmTwoFactorSetup(ctx context.Context, userID, code string) (TwoFactorEnrollment, error) + func (s *Service) DisableTwoFactor(ctx context.Context, userID, code string) error + func (s *Service) ListSessions(ctx context.Context, userID, currentRefreshToken string) ([]Session, error) + func (s *Service) Logout(ctx context.Context, refreshToken string) error + func (s *Service) MarkEmailVerified(ctx context.Context, userID string) error + func (s *Service) Refresh(ctx context.Context, refreshToken, userAgent, ipAddress string) (TokenPair, error) + func (s *Service) RegenerateBackupCodes(ctx context.Context, userID, totpCode string) ([]string, error) + func (s *Service) Register(ctx context.Context, email, password string) (store.User, error) + func (s *Service) RequestEmailVerification(ctx context.Context, userID string) error + func (s *Service) RequestEmailVerificationByEmail(ctx context.Context, email string) error + func (s *Service) RequestPasswordReset(ctx context.Context, email string) error + func (s *Service) ResetPassword(ctx context.Context, rawToken, newPassword string) error + func (s *Service) RevokeOtherSessions(ctx context.Context, userID, currentRefreshToken string) error + func (s *Service) RevokeSession(ctx context.Context, userID, sessionID string) error + func (s *Service) TwoFactorStatus(ctx context.Context, userID string) (TwoFactorStatus, error) + func (s *Service) ValidatePasswordResetToken(ctx context.Context, rawToken string) error + func (s *Service) VerifyEmail(ctx context.Context, rawToken string) error + func (s *Service) VerifyTwoFactorLogin(ctx context.Context, pendingToken, code, userAgent, ipAddress string) (AuthResult, error) + type Session struct + CreatedAt time.Time + ExpiresAt time.Time + ID string + IPAddress string + IsCurrent bool + UserAgent string + type Stores struct + EmailVerifications store.EmailVerificationStore + Lockouts store.LockoutStore + PasswordResets store.PasswordResetStore + PendingTwoFactor store.PendingTwoFactorStore + RefreshTokens store.RefreshTokenStore + TOTP store.TOTPStore + Users store.UserStore + type TokenPair struct + AccessToken string + ExpiresAt time.Time + RefreshToken string + type TwoFactorEnrollment struct + BackupCodes []string + type TwoFactorSetup struct + OTPAuthURL string + Secret string + type TwoFactorStatus struct + Enabled bool + RemainingBackupCodes int + VerifiedAt *time.Time v0.2.0 Aug 25, 2026