toussaint

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 18, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package toussaint implements service logic for manipulating two factor methods.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthenticationWithRecovery

func AuthenticationWithRecovery(recoveryEnabled bool) session.Option

AuthenticationWithRecovery is session's Option. It enables or disables two factor authentication with recovery codes.

func AuthenticationWithTOTP

func AuthenticationWithTOTP(totpEnabled bool) session.Option

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

func Guard(db storage.TwoFactor, renewer session.Renewer) func(http.Handler) http.Handler

Guard returns http middleware which guards from clients accessing given handler without completed two factor authentication.

func IsRecoveryEnabled

func IsRecoveryEnabled(state session.State) bool

IsRecoveryEnabled returns true if given session's owner has recovery codes enabled.

func IsTOTPEnabled

func IsTOTPEnabled(state session.State) bool

IsTOTPEnabled check whether OTP codes are enabled for given session.

func IsTwoFactorEnabled

func IsTwoFactorEnabled(tf models.TwoFactor) bool

IsTwoFactorEnabled checks whether some user has enabled any two factor method.

func IsTwoFactorRequired

func IsTwoFactorRequired(state session.State) bool

IsTwoFactorRequired return true if current session requires two factor authentication.

func NewRecovery

func NewRecovery(name string, codes []string) (*models.Recovery, error)

NewRecovery returns new recovery codes for two factor authentication.

func TwoFactorOnly

func TwoFactorOnly(renewer session.Renewer, redirectURI string) func(http.Handler) http.Handler

TwoFactorOnly accepts request with required two factor only. Otherwise redirects to given redirect URI.

func TwoFactorRequired

func TwoFactorRequired(required bool) session.Option

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

func CollectMethods(tf models.TwoFactor) []Method

CollectMethods build slice of valeus that implements Method interface from multiple slices of Methods.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL