Documentation
¶
Index ¶
- type AWSProvider
- type BackupCode
- type MockProvider
- type SMSCode
- type SMSConfig
- type SMSProvider
- type SMSService
- func (sms *SMSService) Close() error
- func (sms *SMSService) GetConfig() SMSConfig
- func (sms *SMSService) GetProviderStatus() bool
- func (sms *SMSService) GetRemainingAttempts(smsCode *SMSCode) int
- func (sms *SMSService) IsCodeExpired(smsCode *SMSCode) bool
- func (sms *SMSService) SendVerificationCode(phoneNumber string) (*SMSCode, error)
- func (sms *SMSService) ValidatePhoneNumber(phoneNumber string) error
- func (sms *SMSService) VerifyCode(smsCode *SMSCode, inputCode string) (bool, error)
- type TOTPConfig
- type TOTPService
- func (ts *TOTPService) Close() error
- func (ts *TOTPService) GenerateCurrentToken(secret string) (string, error)
- func (ts *TOTPService) GenerateRecoveryCodes(count int) ([]BackupCode, error)
- func (ts *TOTPService) GenerateSecret(userEmail, accountName string) (*TOTPConfig, error)
- func (ts *TOTPService) GetRemainingBackupCodes(backupCodes []BackupCode) int
- func (ts *TOTPService) GetTOTPURL(secret, userEmail, accountName string) string
- func (ts *TOTPService) MarkBackupCodeUsed(backupCodes []BackupCode, codeIndex int) error
- func (ts *TOTPService) ValidateBackupCode(backupCodes []BackupCode, inputCode string) (bool, int)
- func (ts *TOTPService) ValidateSetupToken(secret, token string) bool
- func (ts *TOTPService) ValidateToken(secret, token string) bool
- func (ts *TOTPService) ValidateTokenWithWindow(secret, token string, windowSize uint) bool
- func (ts *TOTPService) VerifySecretFormat(secret string) error
- type TwilioProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AWSProvider ¶
type AWSProvider struct {
// contains filtered or unexported fields
}
AWSProvider implements SMS provider using AWS SNS
func NewAWSProvider ¶
func NewAWSProvider(region, accessKey, secretKey string, logger *logrus.Logger) *AWSProvider
NewAWSProvider creates a new AWS SNS SMS provider
func (*AWSProvider) GetProviderName ¶
func (ap *AWSProvider) GetProviderName() string
func (*AWSProvider) IsHealthy ¶
func (ap *AWSProvider) IsHealthy() bool
func (*AWSProvider) SendSMS ¶
func (ap *AWSProvider) SendSMS(phoneNumber, message string) error
type BackupCode ¶
type BackupCode struct { Code string `json:"code"` Used bool `json:"used"` UsedAt *time.Time `json:"used_at,omitempty"` CreatedAt time.Time `json:"created_at"` }
BackupCode represents a backup recovery code
type MockProvider ¶
type MockProvider struct {
// contains filtered or unexported fields
}
MockProvider implements a mock SMS provider for testing
func NewMockProvider ¶
func NewMockProvider(shouldFail bool, logger *logrus.Logger) *MockProvider
NewMockProvider creates a new mock SMS provider
func (*MockProvider) GetProviderName ¶
func (mp *MockProvider) GetProviderName() string
func (*MockProvider) GetSentCodes ¶
func (mp *MockProvider) GetSentCodes() []string
func (*MockProvider) IsHealthy ¶
func (mp *MockProvider) IsHealthy() bool
func (*MockProvider) SendSMS ¶
func (mp *MockProvider) SendSMS(phoneNumber, message string) error
func (*MockProvider) SetShouldFail ¶
func (mp *MockProvider) SetShouldFail(shouldFail bool)
type SMSCode ¶
type SMSCode struct { Code string `json:"code"` PhoneNumber string `json:"phone_number"` CreatedAt time.Time `json:"created_at"` ExpiresAt time.Time `json:"expires_at"` Attempts int `json:"attempts"` IsUsed bool `json:"is_used"` UsedAt *time.Time `json:"used_at,omitempty"` }
SMSCode represents an SMS verification code
type SMSConfig ¶
type SMSConfig struct { CodeLength int `json:"code_length"` CodeTTL time.Duration `json:"code_ttl"` MaxAttempts int `json:"max_attempts"` RateLimit time.Duration `json:"rate_limit"` DefaultMessage string `json:"default_message"` }
SMSConfig holds SMS service configuration
type SMSProvider ¶
type SMSProvider interface { SendSMS(phoneNumber, message string) error GetProviderName() string IsHealthy() bool }
SMSProvider interface for different SMS providers
type SMSService ¶
type SMSService struct {
// contains filtered or unexported fields
}
SMSService handles SMS-based two-factor authentication
func NewSMSService ¶
func NewSMSService(provider SMSProvider, config SMSConfig, logger *logrus.Logger) *SMSService
NewSMSService creates a new SMS service
func (*SMSService) GetConfig ¶
func (sms *SMSService) GetConfig() SMSConfig
GetConfig returns the SMS service configuration
func (*SMSService) GetProviderStatus ¶
func (sms *SMSService) GetProviderStatus() bool
GetProviderStatus returns the status of the SMS provider
func (*SMSService) GetRemainingAttempts ¶
func (sms *SMSService) GetRemainingAttempts(smsCode *SMSCode) int
GetRemainingAttempts returns remaining verification attempts
func (*SMSService) IsCodeExpired ¶
func (sms *SMSService) IsCodeExpired(smsCode *SMSCode) bool
IsCodeExpired checks if a code is expired
func (*SMSService) SendVerificationCode ¶
func (sms *SMSService) SendVerificationCode(phoneNumber string) (*SMSCode, error)
SendVerificationCode sends an SMS verification code
func (*SMSService) ValidatePhoneNumber ¶
func (sms *SMSService) ValidatePhoneNumber(phoneNumber string) error
ValidatePhoneNumber validates a phone number format
func (*SMSService) VerifyCode ¶
func (sms *SMSService) VerifyCode(smsCode *SMSCode, inputCode string) (bool, error)
VerifyCode verifies an SMS verification code
type TOTPConfig ¶
type TOTPConfig struct { Secret string `json:"secret"` URL string `json:"url"` QRCode []byte `json:"qr_code,omitempty"` BackupCodes []string `json:"backup_codes"` CreatedAt time.Time `json:"created_at"` IsVerified bool `json:"is_verified"` }
TOTPConfig holds TOTP configuration
type TOTPService ¶
type TOTPService struct {
// contains filtered or unexported fields
}
TOTPService handles Time-based One-Time Password operations
func NewTOTPService ¶
func NewTOTPService(issuer string, logger *logrus.Logger) *TOTPService
NewTOTPService creates a new TOTP service
func (*TOTPService) GenerateCurrentToken ¶
func (ts *TOTPService) GenerateCurrentToken(secret string) (string, error)
GenerateCurrentToken generates the current TOTP token for testing
func (*TOTPService) GenerateRecoveryCodes ¶
func (ts *TOTPService) GenerateRecoveryCodes(count int) ([]BackupCode, error)
GenerateRecoveryCodes generates new backup codes (for rotation)
func (*TOTPService) GenerateSecret ¶
func (ts *TOTPService) GenerateSecret(userEmail, accountName string) (*TOTPConfig, error)
GenerateSecret generates a new TOTP secret for a user
func (*TOTPService) GetRemainingBackupCodes ¶
func (ts *TOTPService) GetRemainingBackupCodes(backupCodes []BackupCode) int
GetRemainingBackupCodes returns the count of unused backup codes
func (*TOTPService) GetTOTPURL ¶
func (ts *TOTPService) GetTOTPURL(secret, userEmail, accountName string) string
GetTOTPURL constructs a TOTP URL for manual entry
func (*TOTPService) MarkBackupCodeUsed ¶
func (ts *TOTPService) MarkBackupCodeUsed(backupCodes []BackupCode, codeIndex int) error
MarkBackupCodeUsed marks a backup code as used
func (*TOTPService) ValidateBackupCode ¶
func (ts *TOTPService) ValidateBackupCode(backupCodes []BackupCode, inputCode string) (bool, int)
ValidateBackupCode validates a backup recovery code
func (*TOTPService) ValidateSetupToken ¶
func (ts *TOTPService) ValidateSetupToken(secret, token string) bool
ValidateSetupToken validates a token during initial setup
func (*TOTPService) ValidateToken ¶
func (ts *TOTPService) ValidateToken(secret, token string) bool
ValidateToken validates a TOTP token
func (*TOTPService) ValidateTokenWithWindow ¶
func (ts *TOTPService) ValidateTokenWithWindow(secret, token string, windowSize uint) bool
ValidateTokenWithWindow validates a TOTP token with a time window
func (*TOTPService) VerifySecretFormat ¶
func (ts *TOTPService) VerifySecretFormat(secret string) error
VerifySecretFormat validates that a secret is properly formatted
type TwilioProvider ¶
type TwilioProvider struct {
// contains filtered or unexported fields
}
TwilioProvider implements SMS provider using Twilio
func NewTwilioProvider ¶
func NewTwilioProvider(accountSID, authToken, fromNumber string, logger *logrus.Logger) *TwilioProvider
NewTwilioProvider creates a new Twilio SMS provider
func (*TwilioProvider) GetProviderName ¶
func (tp *TwilioProvider) GetProviderName() string
func (*TwilioProvider) IsHealthy ¶
func (tp *TwilioProvider) IsHealthy() bool
func (*TwilioProvider) SendSMS ¶
func (tp *TwilioProvider) SendSMS(phoneNumber, message string) error