Documentation
¶
Index ¶
- func Register(router forge.Router, basePath string, h *Handler)
- type CodesResponse
- type Config
- type DisableRequest
- type EnableRequest
- type EnableRequest2FA
- type EnableResponse
- type GetStatusRequest
- type Handler
- func (h *Handler) Disable(c forge.Context) error
- func (h *Handler) Enable(c forge.Context) error
- func (h *Handler) GenerateBackupCodes(c forge.Context) error
- func (h *Handler) SendOTP(c forge.Context) error
- func (h *Handler) Status(c forge.Context) error
- func (h *Handler) Verify(c forge.Context) error
- type OTPSentResponse
- type Plugin
- func (p *Plugin) ID() string
- func (p *Plugin) Init(authInst core.Authsome) error
- func (p *Plugin) Migrate() error
- func (p *Plugin) RegisterHooks(_ *hooks.HookRegistry) error
- func (p *Plugin) RegisterRoutes(router forge.Router) error
- func (p *Plugin) RegisterServiceDecorators(_ *registry.ServiceRegistry) error
- type PluginOption
- func WithBackupCodeCount(count int) PluginOption
- func WithBackupCodeLength(length int) PluginOption
- func WithDefaultConfig(cfg Config) PluginOption
- func WithMaxOTPAttempts(max int) PluginOption
- func WithOTPExpiryMinutes(minutes int) PluginOption
- func WithRequireFor2FA(required bool) PluginOption
- func WithTOTPIssuer(issuer string) PluginOption
- func WithTOTPPeriod(period int) PluginOption
- func WithTrustedDeviceDays(days int) PluginOption
- type RegenerateCodesRequest
- type SendOTPRequest
- type Service
- func (s *Service) BackupCodes(ctx context.Context, userID string, count int) ([]string, error)
- func (s *Service) CleanupExpiredDevices(ctx context.Context) error
- func (s *Service) Disable(ctx context.Context, userID string) error
- func (s *Service) Enable(ctx context.Context, userID string, req *EnableRequest) (*TOTPSecret, error)
- func (s *Service) GenerateBackupCodes(ctx context.Context, userID string, count int) ([]string, error)
- func (s *Service) GenerateTOTPSecret(ctx context.Context, userID string) (*TOTPSecret, error)
- func (s *Service) GetStatus(ctx context.Context, userID, deviceID string) (*Status, error)
- func (s *Service) IsTrusted(ctx context.Context, userID, deviceID string) (bool, error)
- func (s *Service) IsTrustedDevice(ctx context.Context, userID, deviceID string) bool
- func (s *Service) ListTrustedDevices(ctx context.Context, userID string) ([]schema.TrustedDevice, error)
- func (s *Service) MarkTrusted(ctx context.Context, userID, deviceID string, days int) error
- func (s *Service) MarkTrustedDevice(ctx context.Context, userID, deviceID string, days int) error
- func (s *Service) RemoveTrustedDevice(ctx context.Context, userID, deviceID string) error
- func (s *Service) SendOTP(ctx context.Context, userID string) (string, error)
- func (s *Service) Verify(ctx context.Context, userID string, req *VerifyRequest) (bool, error)
- func (s *Service) VerifyBackupCode(ctx context.Context, userID, code string) (bool, error)
- func (s *Service) VerifyOTP(ctx context.Context, userID, code string) (bool, error)
- func (s *Service) VerifyTOTP(userID, code string) (bool, error)
- type Status
- type StatusResponse
- type TOTPSecret
- type TwoFABackupCodesResponse
- type TwoFAEnableResponse
- type TwoFAErrorResponse
- type TwoFASendOTPResponse
- type TwoFAStatusDetailResponse
- type TwoFAStatusResponse
- type VerifyRequest
- type VerifyRequest2FA
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CodesResponse ¶
type CodesResponse struct {
Codes []string `json:"codes"`
}
Plugin-specific responses
type Config ¶
type Config struct {
// TOTPIssuer is the issuer name shown in authenticator apps
TOTPIssuer string `json:"totpIssuer"`
// TOTPPeriod is the TOTP time period in seconds
TOTPPeriod int `json:"totpPeriod"`
// TOTPDigits is the number of digits in TOTP code
TOTPDigits int `json:"totpDigits"`
// BackupCodeCount is the number of backup codes to generate
BackupCodeCount int `json:"backupCodeCount"`
// BackupCodeLength is the length of each backup code
BackupCodeLength int `json:"backupCodeLength"`
// OTPExpiryMinutes is the OTP expiry time in minutes
OTPExpiryMinutes int `json:"otpExpiryMinutes"`
// MaxOTPAttempts is the maximum failed OTP attempts before lockout
MaxOTPAttempts int `json:"maxOtpAttempts"`
// TrustedDeviceDays is the number of days a device remains trusted
TrustedDeviceDays int `json:"trustedDeviceDays"`
// RequireFor2FA forces 2FA for all users
RequireFor2FA bool `json:"requireFor2FA"`
}
Config holds the 2FA plugin configuration
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default 2FA plugin configuration
type DisableRequest ¶ added in v0.0.7
type DisableRequest struct {
UserID string `json:"user_id" validate:"required"`
}
type EnableRequest ¶
type EnableRequest struct {
Method string // "totp" or "otp"
}
type EnableRequest2FA ¶ added in v0.0.7
type EnableRequest2FA struct {
UserID string `json:"user_id" validate:"required"`
Method string `json:"method"`
}
Request types
type EnableResponse ¶ added in v0.0.7
type GetStatusRequest ¶ added in v0.0.7
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler exposes HTTP endpoints for 2FA operations
func NewHandler ¶
func (*Handler) SendOTP ¶
SendOTP triggers generation of an OTP code for a user (returns code in response for dev/testing)
type OTPSentResponse ¶
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin implements the plugins.Plugin interface for Two-Factor Authentication
func NewPlugin ¶
func NewPlugin(opts ...PluginOption) *Plugin
NewPlugin creates a new 2FA plugin instance with optional configuration
func (*Plugin) RegisterHooks ¶
func (p *Plugin) RegisterHooks(_ *hooks.HookRegistry) error
func (*Plugin) RegisterRoutes ¶
RegisterRoutes registers 2FA endpoints under the auth base
func (*Plugin) RegisterServiceDecorators ¶
func (p *Plugin) RegisterServiceDecorators(_ *registry.ServiceRegistry) error
type PluginOption ¶
type PluginOption func(*Plugin)
PluginOption is a functional option for configuring the 2FA plugin
func WithBackupCodeCount ¶
func WithBackupCodeCount(count int) PluginOption
WithBackupCodeCount sets the number of backup codes
func WithBackupCodeLength ¶
func WithBackupCodeLength(length int) PluginOption
WithBackupCodeLength sets the backup code length
func WithDefaultConfig ¶
func WithDefaultConfig(cfg Config) PluginOption
WithDefaultConfig sets the default configuration for the plugin
func WithMaxOTPAttempts ¶
func WithMaxOTPAttempts(max int) PluginOption
WithMaxOTPAttempts sets the max OTP attempts
func WithOTPExpiryMinutes ¶
func WithOTPExpiryMinutes(minutes int) PluginOption
WithOTPExpiryMinutes sets the OTP expiry time
func WithRequireFor2FA ¶
func WithRequireFor2FA(required bool) PluginOption
WithRequireFor2FA sets whether 2FA is required for all users
func WithTOTPIssuer ¶
func WithTOTPIssuer(issuer string) PluginOption
WithTOTPIssuer sets the TOTP issuer name
func WithTOTPPeriod ¶
func WithTOTPPeriod(period int) PluginOption
WithTOTPPeriod sets the TOTP time period
func WithTrustedDeviceDays ¶
func WithTrustedDeviceDays(days int) PluginOption
WithTrustedDeviceDays sets the trusted device duration
type RegenerateCodesRequest ¶ added in v0.0.7
type SendOTPRequest ¶ added in v0.0.7
type SendOTPRequest struct {
UserID string `json:"user_id" validate:"required"`
}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides Two-Factor Authentication operations
func NewService ¶
func NewService(r *repo.TwoFARepository, config Config) *Service
func (*Service) BackupCodes ¶
BackupCodes generates cryptographically secure recovery codes for 2FA
func (*Service) CleanupExpiredDevices ¶
CleanupExpiredDevices removes expired trusted device records
func (*Service) Enable ¶
func (s *Service) Enable(ctx context.Context, userID string, req *EnableRequest) (*TOTPSecret, error)
Enable sets up 2FA for a user using the specified method
func (*Service) GenerateBackupCodes ¶
func (s *Service) GenerateBackupCodes(ctx context.Context, userID string, count int) ([]string, error)
GenerateBackupCodes returns a set of backup recovery codes
func (*Service) GenerateTOTPSecret ¶
GenerateTOTPSecret creates a new TOTP secret and provisioning URI
func (*Service) IsTrustedDevice ¶
IsTrustedDevice checks if a device is currently trusted (not expired)
func (*Service) ListTrustedDevices ¶
func (s *Service) ListTrustedDevices(ctx context.Context, userID string) ([]schema.TrustedDevice, error)
ListTrustedDevices returns all trusted devices for a user
func (*Service) MarkTrusted ¶
Trusted devices helpers (stubs)
func (*Service) MarkTrustedDevice ¶
MarkTrustedDevice marks a device as trusted for a specified number of days
func (*Service) RemoveTrustedDevice ¶
RemoveTrustedDevice removes trust for a specific device
func (*Service) SendOTP ¶
SendOTP generates and stores a one-time password; returns the code for delivery
func (*Service) VerifyBackupCode ¶
VerifyBackupCode validates a backup code and marks it as used
type StatusResponse ¶
type StatusResponse = responses.StatusResponse
Response types - use shared responses from core
type TOTPSecret ¶
TOTPSecret represents a generated TOTP secret bundle
type TwoFABackupCodesResponse ¶
type TwoFABackupCodesResponse struct {
Codes []string `json:"codes" example:"12345678,87654321"`
}
type TwoFAEnableResponse ¶
type TwoFAErrorResponse ¶
type TwoFAErrorResponse struct {
Error string `json:"error" example:"Error message"`
}
Response types for 2FA routes
type TwoFASendOTPResponse ¶
type TwoFAStatusResponse ¶
type VerifyRequest ¶
type VerifyRequest struct {
Code string
}