Versions in this module Expand all Collapse all v0 v0.1.1 Nov 12, 2026 v0.1.0 Oct 14, 2026 Changes in this version + const ColConfirmedAt + const ColCreatedAt + const ColDeviceCreatedAt + const ColDeviceExpiresAt + const ColDeviceID + const ColDeviceLastUsed + const ColDeviceTokenHash + const ColDeviceUser + const ColDeviceUserAgent + const ColEnabled + const ColFailures + const ColIssuer + const ColLastStep + const ColLockedUntil + const ColMethod + const ColRecoveryHash + const ColRecoveryID + const ColRecoverySealed + const ColRecoverySeq + const ColRecoveryUsed + const ColRecoveryUser + const ColSecret + const ColUserID + const DefaultCodeTTL + const DefaultIssuer + const DefaultRecoveryCodeLength + const DefaultRecoveryCodes + const DefaultTrustedDeviceAge + const Digits + const EndpointCheck + const EndpointConfirm + const EndpointDevices + const EndpointDisable + const EndpointEnroll + const EndpointForgetDevice + const EndpointReauthenticate + const EndpointRecoveryCodes + const EndpointRemoveFactor + const EndpointSecurityKeyChallenge + const EndpointSecurityKeyRegisterBegin + const EndpointSecurityKeyRegisterFinish + const EndpointSend + const EndpointStatus + const EndpointTOTPURI + const EndpointVerify + const EndpointViewRecoveryCodes + const KeyLabelRecoveryCodes + const LockDuration + const LongDigits + const MaxFailures + const MaxIssuerLength + const MaxTrustedDeviceAge + const MinImportSecretBytes + const MinRecoveryCodeLength + const PluginName + const PurposeCode + const Skew + const Step + const TableAliasDevice + const TableAliasFactor + const TableAliasMethod + const TableAliasRecover + const TableNameDevice + const TableNameFactor + const TableNameMethod + const TableNameRecovery + var CredentialSignIns = []auth.EndpointID + var DeviceCreatedAt = sqlb.Col[time.Time](TableDevice, ColDeviceCreatedAt) + var DeviceExpiresAt = sqlb.Col[time.Time](TableDevice, ColDeviceExpiresAt) + var DeviceID = sqlb.Col[string](TableDevice, ColDeviceID) + var DeviceLastUsed = sqlb.Col[*time.Time](TableDevice, ColDeviceLastUsed) + var DeviceTokenHash = sqlb.Col[[]byte](TableDevice, ColDeviceTokenHash) + var DeviceUser = sqlb.Col[string](TableDevice, ColDeviceUser) + var DeviceUserAgent = sqlb.Col[string](TableDevice, ColDeviceUserAgent) + var Enabled = sqlb.Col[bool](auth.TableUser, ColEnabled) + var ErrAlreadyEnabled = auth.NewError("twofactor.already_enabled", http.StatusConflict, ...) + var ErrBadCodeTTL = errors.New("twofactor: CodeTTL must be positive") + var ErrBadDigits = errors.New("twofactor: Digits must be 6 or 8") + var ErrBadLockout = errors.New(...) + var ErrBadPeriod = errors.New("twofactor: Period must be a positive number of whole seconds") + var ErrBadRecoveryCodes = errors.New(...) + var ErrBadRecoveryLen = errors.New("twofactor: RecoveryCodeLength must be at least MinRecoveryCodeLength") + var ErrBadRecoveryStorage = errors.New("twofactor: RecoveryCodeStorage must be StoreHashed or StoreEncrypted") + var ErrBadTrustAge = errors.New(...) + var ErrCodeInvalid = auth.NewError("twofactor.code_invalid", http.StatusBadRequest, "This code is not right.") + var ErrDeviceNotFound = auth.NewError("twofactor.device_not_found", http.StatusNotFound, "Not found.") + var ErrFactorNotEnrolled = auth.NewError("twofactor.factor_not_enrolled", http.StatusBadRequest, ...) + var ErrFactorNotFound = auth.NewError("twofactor.factor_not_found", http.StatusNotFound, "Not found.") + var ErrIssuerInvalid = auth.NewError("twofactor.issuer_invalid", http.StatusBadRequest, ...) + var ErrLocked = auth.NewError("twofactor.locked", http.StatusTooManyRequests, ...) + var ErrMethodInvalid = auth.NewError("twofactor.method_invalid", http.StatusBadRequest, ...) + var ErrNoChannel = auth.NewError("twofactor.no_channel", http.StatusConflict, ...) + var ErrNoEncryptionKey = errors.New(...) + var ErrNoMethod = errors.New("twofactor: WithoutTOTP needs DeliveredCodes, or nobody can enrol") + var ErrNotCodeMethod = auth.NewError("twofactor.not_code_method", http.StatusConflict, ...) + var ErrNotEnrolled = auth.NewError("twofactor.not_enrolled", http.StatusConflict, "Start two-factor setup first.") + var ErrNotTOTP = auth.NewError("twofactor.not_totp", http.StatusConflict, ...) + var ErrProofRequired = auth.NewError("twofactor.proof_required", http.StatusBadRequest, ...) + var ErrRecoveryCodesHidden = auth.NewError("twofactor.recovery_codes_hidden", http.StatusConflict, ...) + var ErrRecoveryStorageNeedsSecret = errors.New("twofactor: RecoveryCodeStorage(StoreEncrypted) needs auth.WithSecret") + var ErrSecretInvalid = auth.NewError("twofactor.secret_invalid", http.StatusBadRequest, ...) + var ErrSecretUnreadable = auth.NewError("twofactor.secret_unreadable", http.StatusServiceUnavailable, ...) + var ErrSecurityKeyInvalid = auth.NewError("twofactor.security_key_invalid", http.StatusUnauthorized, ...) + var ErrTrustDisabled = auth.NewError("twofactor.trust_disabled", http.StatusBadRequest, ...) + var ErrTrustNeedsSession = auth.NewError("twofactor.trust_needs_session", http.StatusBadRequest, ...) + var FactorConfirmedAt = sqlb.Col[*time.Time](TableFactor, ColConfirmedAt) + var FactorCreatedAt = sqlb.Col[time.Time](TableFactor, ColCreatedAt) + var FactorFailures = sqlb.Col[int](TableFactor, ColFailures) + var FactorIssuer = sqlb.Col[string](TableFactor, ColIssuer) + var FactorLastStep = sqlb.Col[int64](TableFactor, ColLastStep) + var FactorLockedUntil = sqlb.Col[*time.Time](TableFactor, ColLockedUntil) + var FactorMethod = sqlb.Col[string](TableFactor, ColMethod) + var FactorSecret = sqlb.Col[string](TableFactor, ColSecret) + var FactorUserID = sqlb.Col[string](TableFactor, ColUserID) + var MethodConfirmedAt = sqlb.Col[*time.Time](TableMethod, ColConfirmedAt) + var MethodCreatedAt = sqlb.Col[time.Time](TableMethod, ColCreatedAt) + var MethodIssuer = sqlb.Col[string](TableMethod, ColIssuer) + var MethodKind = sqlb.Col[string](TableMethod, ColMethod) + var MethodLastStep = sqlb.Col[int64](TableMethod, ColLastStep) + var MethodSecret = sqlb.Col[string](TableMethod, ColSecret) + var MethodUserID = sqlb.Col[string](TableMethod, ColUserID) + var MethodValues = []Method + var RecoveryHash = sqlb.Col[[]byte](TableRecovery, ColRecoveryHash) + var RecoveryID = sqlb.Col[string](TableRecovery, ColRecoveryID) + var RecoverySealed = sqlb.Col[string](TableRecovery, ColRecoverySealed) + var RecoverySeq = sqlb.Col[int](TableRecovery, ColRecoverySeq) + var RecoveryStorageValues = []RecoveryStorage + var RecoveryUsed = sqlb.Col[*time.Time](TableRecovery, ColRecoveryUsed) + var RecoveryUser = sqlb.Col[string](TableRecovery, ColRecoveryUser) + var TableDevice = sqlb.Table + var TableFactor = sqlb.Table + var TableMethod = sqlb.Table + var TableRecovery = sqlb.Table + func AskEverySignIn(_ context.Context, in PolicyRequest) (bool, error) + func Bindings(c *TwoFactorColumns) []sqlb.Binding + func DefaultPolicy(_ context.Context, in PolicyRequest) (bool, error) + type CodeRequest struct + Code string + DisableSession bool + Method Method + Password auth.Token + SecurityKey *SecurityKeyResponse + TrustDevice bool + type DevicesResult struct + Devices []TrustedDevice + type EnrollRequest struct + Issuer string + Method Method + Password auth.Token + Proof *FactorProof + type EnrollResult struct + Enabled bool + Method Method + RecoveryCodes []string + Secret string + URL string + type EnrolmentRule func(ctx context.Context, a *auth.Auth, userID string) (bool, error) + type Factor struct + CreatedAt time.Time + ID string + LastUsedAt *time.Time + Method Method + Name string + Primary bool + type FactorProof struct + Code string + Method Method + SecurityKey *SecurityKeyResponse + type ForgetDeviceRequest struct + All bool + ID string + type LabelFunc func(ctx context.Context, a *auth.Auth, u auth.User) string + type Method string + const MethodDelivered + const MethodSecurityKey + const MethodTOTP + type Option func(*Plugin) + func AccountLabel(fn LabelFunc) Option + func CodeTTL(d time.Duration) Option + func DeliveredCodes() Option + func Issuer(name string) Option + func Lockout(maxFailures int, d time.Duration) Option + func ReadableTOTPURI() Option + func RecoveryCodeCount(n int) Option + func RecoveryCodeGenerator(fn func() []string) Option + func RecoveryCodeLength(n int) Option + func RecoveryCodeStorage(s RecoveryStorage) Option + func RequireEnrolment(rule EnrolmentRule) Option + func RequirePassword() Option + func SkipVerificationOnEnable() Option + func TrustDevices(maxAge time.Duration) Option + func WithDigits(n int) Option + func WithEncryptionKey(key []byte) Option + func WithPeriod(d time.Duration) Option + func WithPolicy(fn Policy) Option + func WithSealer(s auth.Sealer) Option + func WithSecurityKeys(s SecurityKeyStore) Option + func WithoutTOTP() Option + type PasswordChecker interface + HasPassword func(ctx context.Context, userID string) (bool, error) + Verify func(ctx context.Context, password auth.Token) error + type PasswordRequest struct + Password auth.Token + type Plugin struct + func New(opts ...Option) *Plugin + func (p *Plugin) CheckCode(ctx context.Context, code string) error + func (p *Plugin) Columns() []auth.ColumnExtension + func (p *Plugin) Confirm(ctx context.Context, code string) (RecoveryCodes, error) + func (p *Plugin) CredentialChanged(ctx context.Context, userID string) error + func (p *Plugin) Devices(ctx context.Context) ([]TrustedDevice, error) + func (p *Plugin) Disable(ctx context.Context, code string) error + func (p *Plugin) DisableFor(ctx context.Context, userID string) error + func (p *Plugin) DisableWith(ctx context.Context, in CodeRequest) error + func (p *Plugin) EnableFor(ctx context.Context, userID string) error + func (p *Plugin) Enroll(ctx context.Context) (EnrollResult, error) + func (p *Plugin) EnrollWith(ctx context.Context, in EnrollRequest) (EnrollResult, error) + func (p *Plugin) FactorOf(ctx context.Context, userID string) (method string, enabled bool, err error) + func (p *Plugin) ForgetDevice(ctx context.Context, in ForgetDeviceRequest) error + func (p *Plugin) ImportTOTP(ctx context.Context, userID string, secret string) error + func (p *Plugin) Init(a *auth.Auth) error + func (p *Plugin) Methods() []Method + func (p *Plugin) Name() string + func (p *Plugin) Operations() []auth.Operation + func (p *Plugin) OptionErr() error + func (p *Plugin) RateLimits() []auth.RateRule + func (p *Plugin) Reauthenticate(ctx context.Context, in ReauthenticateRequest) (auth.Reauthentication, error) + func (p *Plugin) RegenerateRecoveryCodes(ctx context.Context, code string) (RecoveryCodes, error) + func (p *Plugin) RegenerateRecoveryCodesWith(ctx context.Context, in CodeRequest) (RecoveryCodes, error) + func (p *Plugin) RemoveFactor(ctx context.Context, in RemoveFactorRequest) (RemoveFactorResult, error) + func (p *Plugin) Reset(ctx context.Context, userID string) error + func (p *Plugin) SecondFactorRequired(ctx context.Context, userID string) (bool, error) + func (p *Plugin) SecondFactorRequiredForSignIn(ctx context.Context, in auth.SignInAttempt) (bool, error) + func (p *Plugin) SecurityKeyChallengeFor(ctx context.Context) (SecurityKeyChallenge, error) + func (p *Plugin) SecurityKeyRegisterBegin(ctx context.Context, in SecurityKeyRegisterBeginRequest) (SecurityKeyChallenge, error) + func (p *Plugin) SecurityKeyRegisterFinish(ctx context.Context, in SecurityKeyRegisterFinishRequest) (SecurityKeyRegistered, error) + func (p *Plugin) Send(ctx context.Context) error + func (p *Plugin) SessionTasks() []auth.SessionTask + func (p *Plugin) SessionTasksFor(ctx context.Context, in auth.SignInAttempt) ([]auth.SessionTaskID, error) + func (p *Plugin) Status(ctx context.Context) (Status, error) + func (p *Plugin) Sweep(ctx context.Context, cutoff time.Time) (int64, error) + func (p *Plugin) TOTPURI(ctx context.Context, in PasswordRequest) (TOTPURIResult, error) + func (p *Plugin) Tables() []sqlb.Table + func (p *Plugin) TypedMigrations(engine string, t auth.SQLTypes) ([]auth.Migration, error) + func (p *Plugin) Unlock(ctx context.Context, userID string) error + func (p *Plugin) UserTables() []auth.UserTable + func (p *Plugin) Validate(cfg *auth.Config) error + func (p *Plugin) Verify(ctx context.Context, code string) error + func (p *Plugin) VerifyWith(ctx context.Context, in CodeRequest) error + func (p *Plugin) ViewRecoveryCodes(ctx context.Context, in PasswordRequest) (RecoveryCodes, error) + type Policy func(ctx context.Context, in PolicyRequest) (bool, error) + type PolicyRequest struct + DeviceTrusted bool + type ReauthenticateRequest struct + Code string + Method Method + SecurityKey *SecurityKeyResponse + Ticket auth.WireToken + type RecoveryCodes struct + Codes []string + type RecoveryStorage string + const StoreEncrypted + const StoreHashed + type RemoveFactorRequest struct + ID string + Method Method + Password auth.Token + Proof FactorProof + type RemoveFactorResult struct + Enabled bool + type SecurityKey struct + AAGUID string + CreatedAt time.Time + ID string + LastUsedAt *time.Time + Name string + Transports []string + type SecurityKeyChallenge struct + Ceremony string + Options json.RawMessage + type SecurityKeyRegisterBeginRequest struct + AuthenticatorAttachment string + Password auth.Token + type SecurityKeyRegisterFinishRequest struct + Ceremony string + Credential json.RawMessage + Name string + Proof *FactorProof + type SecurityKeyRegistered struct + Key SecurityKey + RecoveryCodes []string + type SecurityKeyRegistration struct + Ceremony string + Credential json.RawMessage + Name string + type SecurityKeyResponse struct + Ceremony string + Credential json.RawMessage + type SecurityKeyStore interface + BeginSecurityKeyAssertion func(ctx context.Context, userID string) (SecurityKeyChallenge, error) + BeginSecurityKeyRegistration func(ctx context.Context, u auth.User, attachment string) (SecurityKeyChallenge, error) + FinishSecurityKeyAssertion func(ctx context.Context, userID string, in SecurityKeyResponse) error + FinishSecurityKeyRegistration func(ctx context.Context, userID string, in SecurityKeyRegistration) (SecurityKey, error) + RemoveSecurityKey func(ctx context.Context, userID, id string) error + RemoveSecurityKeys func(ctx context.Context, userID string) error + SecurityKeys func(ctx context.Context, userID string) ([]SecurityKey, error) + type Status struct + Enabled bool + Factors []Factor + Method Method + Methods []Method + TrustDevices bool + type TOTPURIResult struct + URL string + type TrustedDevice struct + CreatedAt time.Time + Current bool + ExpiresAt time.Time + ID string + LastUsed *time.Time + UserAgent string + type TwoFactorColumns struct + TwoFactorEnabled bool