Documentation
¶
Index ¶
- Constants
- func GenerateBackupCodes() ([]string, error)
- func GenerateBatchID() (string, error)
- func GenerateQRCode(uri string) (string, error)
- func GenerateSecret() (string, error)
- func GenerateTOTP(secret string, timestamp time.Time) (string, error)
- func GenerateTOTPURI(config TOTPConfig) string
- func HashBackupCode(code string) (string, error)
- func HashToken(token string) string
- func VerifyBackupCode(code, hash string) bool
- func VerifyTOTP(secret, code string) (bool, error)
- type Handler
- func (h *Handler) CheckSensitiveVerification(e *core.RequestEvent) error
- func (h *Handler) CreateChallenge(e *core.RequestEvent) error
- func (h *Handler) Enroll(e *core.RequestEvent) error
- func (h *Handler) GenerateBackupCodes(e *core.RequestEvent) error
- func (h *Handler) GetAssuranceLevel(e *core.RequestEvent) error
- func (h *Handler) ListFactors(e *core.RequestEvent) error
- func (h *Handler) RegenerateBackupCodes(e *core.RequestEvent) error
- func (h *Handler) RegisterRoutes(e *core.ServeEvent)
- func (h *Handler) Unenroll(e *core.RequestEvent) error
- func (h *Handler) Verify(e *core.RequestEvent) error
- func (h *Handler) VerifyEnrollment(e *core.RequestEvent) error
- func (h *Handler) VerifySensitiveOperation(e *core.RequestEvent) error
- type TOTPConfig
Constants ¶
const ( // TOTPSecretLength is the length of the TOTP secret in bytes TOTPSecretLength = 20 // TOTPDigits is the number of digits in a TOTP code TOTPDigits = 6 // TOTPPeriod is the time step in seconds TOTPPeriod = 30 // TOTPSkew allows for clock drift (1 period before/after) TOTPSkew = 1 // BackupCodeCount is the number of backup codes generated BackupCodeCount = 10 // BackupCodeLength is the length of each backup code BackupCodeLength = 8 // ChallengeExpiryMinutes is how long a challenge remains valid ChallengeExpiryMinutes = 5 // SensitiveOpExpiryMinutes is how long a sensitive operation verification is valid SensitiveOpExpiryMinutes = 10 // QRCodeSize is the size of the QR code image in pixels QRCodeSize = 256 )
const (
// IssuerName is the name shown in authenticator apps
IssuerName = "NannyAPI"
)
Variables ¶
This section is empty.
Functions ¶
func GenerateBackupCodes ¶
GenerateBackupCodes generates a set of single-use backup codes
func GenerateBatchID ¶
GenerateBatchID generates a unique ID for a batch of backup codes
func GenerateQRCode ¶
GenerateQRCode generates a QR code PNG image as base64 string
func GenerateSecret ¶
GenerateSecret generates a cryptographically secure random secret for TOTP
func GenerateTOTP ¶
GenerateTOTP generates a TOTP code for the given secret and time
func GenerateTOTPURI ¶
func GenerateTOTPURI(config TOTPConfig) string
GenerateTOTPURI creates the otpauth:// URI for authenticator apps
func HashBackupCode ¶
HashBackupCode creates a secure hash of a backup code
func VerifyBackupCode ¶
VerifyBackupCode checks if a provided code matches a stored hash
func VerifyTOTP ¶
VerifyTOTP verifies a TOTP code against the secret Returns true if the code is valid for current time ± skew
Types ¶
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler manages MFA operations
func (*Handler) CheckSensitiveVerification ¶
func (h *Handler) CheckSensitiveVerification(e *core.RequestEvent) error
CheckSensitiveVerification checks if a sensitive operation verification is valid
func (*Handler) CreateChallenge ¶
func (h *Handler) CreateChallenge(e *core.RequestEvent) error
CreateChallenge creates an MFA challenge for verification
func (*Handler) Enroll ¶
func (h *Handler) Enroll(e *core.RequestEvent) error
Enroll starts MFA enrollment for the authenticated user
func (*Handler) GenerateBackupCodes ¶
func (h *Handler) GenerateBackupCodes(e *core.RequestEvent) error
GenerateBackupCodes generates new backup codes (requires verified MFA)
func (*Handler) GetAssuranceLevel ¶
func (h *Handler) GetAssuranceLevel(e *core.RequestEvent) error
GetAssuranceLevel returns the current authenticator assurance level
func (*Handler) ListFactors ¶
func (h *Handler) ListFactors(e *core.RequestEvent) error
ListFactors returns all MFA factors for the authenticated user
func (*Handler) RegenerateBackupCodes ¶
func (h *Handler) RegenerateBackupCodes(e *core.RequestEvent) error
RegenerateBackupCodes regenerates backup codes with verification
func (*Handler) RegisterRoutes ¶
func (h *Handler) RegisterRoutes(e *core.ServeEvent)
RegisterRoutes registers MFA API routes
func (*Handler) Unenroll ¶
func (h *Handler) Unenroll(e *core.RequestEvent) error
Unenroll disables MFA for the user
func (*Handler) Verify ¶
func (h *Handler) Verify(e *core.RequestEvent) error
Verify verifies an MFA challenge
func (*Handler) VerifyEnrollment ¶
func (h *Handler) VerifyEnrollment(e *core.RequestEvent) error
VerifyEnrollment completes MFA enrollment by verifying the TOTP code
func (*Handler) VerifySensitiveOperation ¶
func (h *Handler) VerifySensitiveOperation(e *core.RequestEvent) error
VerifySensitiveOperation verifies MFA for a sensitive operation
type TOTPConfig ¶
TOTPConfig holds configuration for TOTP generation