Documentation ¶
Overview ¶
Package toussaint implements service logic for manipulating two factor methods.
Index ¶
- func AuthenticationWithRecovery(recoveryEnabled bool) session.Option
- func AuthenticationWithTOTP(totpEnabled bool) session.Option
- func Cleaner(renewer session.Renewer, killer session.Killer, redirectURI string) func(next http.Handler) http.Handler
- func Find(s []Method, userID string, f func(m models.TwoFactorMethod) bool) *models.TwoFactorMethod
- func Guard(db storage.TwoFactor, renewer session.Renewer) func(http.Handler) http.Handler
- func IsRecoveryEnabled(state session.State) bool
- func IsTOTPEnabled(state session.State) bool
- func IsTwoFactorEnabled(tf models.TwoFactor) bool
- func IsTwoFactorRequired(state session.State) bool
- func NewRecovery(name string, codes []string) (*models.Recovery, error)
- func TwoFactorOnly(renewer session.Renewer, redirectURI string) func(http.Handler) http.Handler
- func TwoFactorRequired(required bool) session.Option
- type CodeValidator
- type Method
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthenticationWithRecovery ¶
AuthenticationWithRecovery is session's Option. It enables or disables two factor authentication with recovery codes.
func AuthenticationWithTOTP ¶
AuthenticationWithTOTP is session's Option. It enables or disables two factor authentication with OTP codes.
func Cleaner ¶
func Cleaner(renewer session.Renewer, killer session.Killer, redirectURI string) func(next http.Handler) http.Handler
Cleaner purges current session if it has enabled two factor authentication and redirects user to given redirect URI.
Sessions with valid two factor authenticate will pass this middleware without any effects.
func Find ¶
func Find(s []Method, userID string, f func(m models.TwoFactorMethod) bool) *models.TwoFactorMethod
Find returns first two factor method for user with given user id which is predictable by given function.
func Guard ¶
Guard returns http middleware which guards from clients accessing given handler without completed two factor authentication.
func IsRecoveryEnabled ¶
IsRecoveryEnabled returns true if given session's owner has recovery codes enabled.
func IsTOTPEnabled ¶
IsTOTPEnabled check whether OTP codes are enabled for given session.
func IsTwoFactorEnabled ¶
IsTwoFactorEnabled checks whether some user has enabled any two factor method.
func IsTwoFactorRequired ¶
IsTwoFactorRequired return true if current session requires two factor authentication.
func NewRecovery ¶
NewRecovery returns new recovery codes for two factor authentication.
func TwoFactorOnly ¶
TwoFactorOnly accepts request with required two factor only. Otherwise redirects to given redirect URI.
func TwoFactorRequired ¶
TwoFactorRequired is session's Option. It forces session's owner to authenticate with two factor method.
Types ¶
type CodeValidator ¶
type CodeValidator interface { // Validate given code against implemented authentication // method. Validate(ctx context.Context, code string) bool }
CodeValidator validates given code against implemented two factor authentication.
func ValidatorComposite ¶
func ValidatorComposite(validators ...CodeValidator) CodeValidator
ValidatorComposite turns multiple code validators into single one.
func ValidatorRecovery ¶
func ValidatorRecovery(tf storage.TwoFactor, userID string) CodeValidator
ValidatorRecovery returns validator for recovery codes stored in given two factor storage.
func ValidatorTOTP ¶
func ValidatorTOTP(tf models.TwoFactor) CodeValidator
ValidatorTOTP returns validator for one time codes stored in two factor methods model.
type Method ¶
type Method interface {
Method(userID string) models.TwoFactorMethod
}
Method implements method function which returns query-able two factor data.
func CollectMethods ¶
CollectMethods build slice of valeus that implements Method interface from multiple slices of Methods.