mfa

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: MIT Imports: 24 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 MarkChallengeUsed

func MarkChallengeUsed(id string) error

func SendEmailOTP

func SendEmailOTP(to, code 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
}

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