twofactor

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: AGPL-3.0, MIT Imports: 4 Imported by: 0

Documentation

Overview

Package twofactor provides authentication strategy, to authenticate HTTP requests based on one time password(otp).

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidOTP = errors.New("strategies/twofactor: Invalid one time password")

ErrInvalidOTP is returned by twofactor strategy, When the user-supplied an invalid one time password and verification process failed.

View Source
var ErrMissingOTP = errors.New("strategies/twofactor: One-time password missing or empty")

ErrMissingOTP is returned by Parser, When one-time password missing or empty in HTTP request.

Functions

This section is empty.

Types

type Manager

type Manager interface {
	// Enabled check if two factor for user enabled.
	Enabled(user auth.Info) bool
	// Load return user OTP Verifier or error.
	Load(user auth.Info) (Verifier, error)
	// Store user OTP Verifier.
	Store(user auth.Info, v Verifier) error
}

Manager load and store user OTP Verifier.

type Parser

type Parser interface {
	GetOTP(r *http.Request) (string, error)
}

Parser parse and extract one-time password from incoming HTTP request.

func CookieParser

func CookieParser(key string) Parser

CookieParser return a one-time password parser, where otp extracted form HTTP Cookie.

func JSONBodyParser

func JSONBodyParser(key string) Parser

JSONBodyParser return a one-time password parser, where otp extracted form request body.

func QueryParser

func QueryParser(key string) Parser

QueryParser return a one-time password parser, where otp extracted form HTTP query string.

func XHeaderParser

func XHeaderParser(header string) Parser

XHeaderParser return a one-time password parser, where otp extracted form "X-" header.

type TwoFactor

type TwoFactor struct {
	// Primary strategy that authenticates the user before verifying the one time password.
	// The primary strategy Typically of type basic or LDAP.
	Primary auth.Strategy
	Parser  Parser
	Manager Manager
}

TwoFactor represents two factor authentication strategy.

type Verifier

type Verifier interface {
	// Verify user one-time password.
	Verify(pin string) (bool, error)
}

Verifier represents one-time password verification.

Jump to

Keyboard shortcuts

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