mfa

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package mfa implements TOTP and WebAuthn multi-factor authentication.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfirmTOTP

func ConfirmTOTP(ctx context.Context, st store.MFAStore, kp bcrypto.KeyProvider, userID uuid.UUID, code string) error

ConfirmTOTP verifies the first code after enrollment and enables the credential.

func VerifyTOTP

func VerifyTOTP(ctx context.Context, st store.MFAStore, kp bcrypto.KeyProvider, userID uuid.UUID, code string) error

VerifyTOTP checks a TOTP code for an already-enrolled user.

Types

type TOTPEnrollResponse

type TOTPEnrollResponse struct {
	CredentialID uuid.UUID `json:"credential_id"`
	Secret       string    `json:"secret"`  // base32, shown once for manual entry
	OTPURI       string    `json:"otp_uri"` // otpauth:// URI for QR codes
}

TOTPEnrollResponse is returned when a user begins TOTP enrollment.

func EnrollTOTP

EnrollTOTP generates a new TOTP secret for the user and stores it (disabled until confirmed).

type WAHandler

type WAHandler struct {
	// contains filtered or unexported fields
}

WAHandler wraps the go-webauthn library and the store.

func NewWAHandler

func NewWAHandler(rpID, rpDisplayName string, origins []string, st store.MFAStore) (*WAHandler, error)

NewWAHandler creates a WebAuthn handler.

func (*WAHandler) BeginLogin

func (h *WAHandler) BeginLogin(ctx context.Context, user *model.User) (optionsJSON []byte, sessionID uuid.UUID, err error)

BeginLogin starts an assertion flow.

func (*WAHandler) BeginRegistration

func (h *WAHandler) BeginRegistration(ctx context.Context, user *model.User) (optionsJSON []byte, sessionID uuid.UUID, err error)

BeginRegistration starts credential enrollment and returns challenge options + session ID.

func (*WAHandler) FinishLogin

func (h *WAHandler) FinishLogin(ctx context.Context, user *model.User, sessionID uuid.UUID, r *http.Request) (amr string, err error)

FinishLogin verifies the assertion from the HTTP request body and updates sign count. Returns "hwk" as the AMR value (hardware key / platform authenticator).

func (*WAHandler) FinishRegistration

func (h *WAHandler) FinishRegistration(ctx context.Context, user *model.User, sessionID uuid.UUID, r *http.Request, deviceName string) (*model.WebAuthnCredential, error)

FinishRegistration completes enrollment from the HTTP request body.

type WAUser

type WAUser struct {
	// contains filtered or unexported fields
}

WAUser adapts model.User to the webauthn.User interface.

func (*WAUser) WebAuthnCredentials

func (w *WAUser) WebAuthnCredentials() []webauthn.Credential

func (*WAUser) WebAuthnDisplayName

func (w *WAUser) WebAuthnDisplayName() string

func (*WAUser) WebAuthnID

func (w *WAUser) WebAuthnID() []byte

func (*WAUser) WebAuthnName

func (w *WAUser) WebAuthnName() string

Jump to

Keyboard shortcuts

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