mfa

package
v1.6.8 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: GPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMfaChallenge

func CreateMfaChallenge(challenge MfaChallenge) error

func GenerateEmailOTP

func GenerateEmailOTP() (string, error)

func GenerateTotpSecret

func GenerateTotpSecret(username, issuer string) (secret string, otpauthURL string, err error)

func HandleMfa

func HandleMfa(w http.ResponseWriter, r *http.Request)

HandleMfa handles multi-factor authentication requests. @Summary Multi-factor authentication @Description Renders the MFA verification or enrollment page (GET) or processes the MFA code (POST). @Tags mfa @Accept x-www-form-urlencoded @Produce html @Param challenge_id query string false "MFA challenge ID (GET)" @Param challenge_id formData string false "MFA challenge ID (POST)" @Param code formData string false "Verification code (POST)" @Param totp_secret formData string false "TOTP secret for enrollment (POST)" @Param trust_device formData string false "Whether to trust the device (POST)" @Success 200 {string} string "MFA form (GET)" @Success 302 {string} string "Redirect back to client with code after success (POST)" @Router /oauth2/mfa [get] @Router /oauth2/mfa [post]

func IncrementFailedAttempts added in v1.4.0

func IncrementFailedAttempts(id string) error

func MarkChallengeUsed

func MarkChallengeUsed(id string) error

func SendEmailOTP

func SendEmailOTP(to, code string) error

func SendPasswordResetEmail added in v1.6.0

func SendPasswordResetEmail(to, resetURL string) error

func SendTestEmail added in v1.5.8

func SendTestEmail(to string) error

func SendVerificationEmail added in v1.5.8

func SendVerificationEmail(to, verifyURL string) error

func UpdateChallengeCode

func UpdateChallengeCode(id, code string) error

func ValidateTotpCode

func ValidateTotpCode(secret, code string) bool

Types

type LoginState

type LoginState struct {
	RedirectURI         string `json:"redirect_uri"`
	State               string `json:"state"`
	ClientID            string `json:"client_id"`
	Scope               string `json:"scope"`
	Nonce               string `json:"nonce"`
	CodeChallenge       string `json:"code_challenge"`
	CodeChallengeMethod string `json:"code_challenge_method"`
}

type MfaChallenge

type MfaChallenge struct {
	ID             string
	UserID         string
	Method         string
	Code           string
	LoginState     string
	CreatedAt      time.Time
	ExpiresAt      time.Time
	Used           bool
	FailedAttempts int
	OtpSentAt      *time.Time
}

func MfaChallengeByID

func MfaChallengeByID(id string) (*MfaChallenge, error)

Jump to

Keyboard shortcuts

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