twofa

package module
v0.0.0-...-f9d256a Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TwoFAConfig

type TwoFAConfig struct {
	SecretKey string `json:"secret_key"`
	Issuer    string `json:"issuer"`
	Algorithm string `json:"algorithm"`
}

TwoFAConfig holds 2FA provider configuration

func DefaultTwoFAConfig

func DefaultTwoFAConfig() *TwoFAConfig

DefaultTwoFAConfig returns default 2FA configuration

type TwoFAProvider

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

TwoFAProvider implements Two-Factor Authentication

func NewTwoFAProvider

func NewTwoFAProvider(config *TwoFAConfig, logger *logrus.Logger) *TwoFAProvider

NewTwoFAProvider creates a new 2FA provider

func (*TwoFAProvider) Authenticate

func (tp *TwoFAProvider) Authenticate(ctx context.Context, request *types.AuthRequest) (*types.AuthResponse, error)

Authenticate authenticates a user with 2FA

func (*TwoFAProvider) Authorize

Authorize authorizes a user

func (*TwoFAProvider) CheckPermission

func (tp *TwoFAProvider) CheckPermission(ctx context.Context, request *types.PermissionRequest) (*types.PermissionResponse, error)

CheckPermission checks if a user has a specific permission

func (*TwoFAProvider) Close

func (tp *TwoFAProvider) Close() error

Close closes the provider

func (*TwoFAProvider) Configure

func (tp *TwoFAProvider) Configure(config map[string]interface{}) error

Configure configures the 2FA provider

func (*TwoFAProvider) GenerateSecret

func (tp *TwoFAProvider) GenerateSecret(ctx context.Context, userID, userEmail string) (*TwoFASecret, error)

GenerateSecret generates a new 2FA secret for a user

func (*TwoFAProvider) GetConnectionInfo

func (tp *TwoFAProvider) GetConnectionInfo() *types.ConnectionInfo

GetConnectionInfo returns connection information

func (*TwoFAProvider) GetName

func (tp *TwoFAProvider) GetName() string

GetName returns the provider name

func (*TwoFAProvider) GetStats

func (tp *TwoFAProvider) GetStats(ctx context.Context) (*types.AuthStats, error)

GetStats returns provider statistics

func (*TwoFAProvider) GetSupportedFeatures

func (tp *TwoFAProvider) GetSupportedFeatures() []types.AuthFeature

GetSupportedFeatures returns supported features

func (*TwoFAProvider) HealthCheck

func (tp *TwoFAProvider) HealthCheck(ctx context.Context) error

HealthCheck performs health check

func (*TwoFAProvider) IsConfigured

func (tp *TwoFAProvider) IsConfigured() bool

IsConfigured returns whether the provider is configured

func (*TwoFAProvider) RefreshToken

RefreshToken refreshes a 2FA token

func (*TwoFAProvider) RevokeToken

func (tp *TwoFAProvider) RevokeToken(ctx context.Context, request *types.TokenRevocationRequest) error

RevokeToken revokes a 2FA token

func (*TwoFAProvider) ValidateToken

ValidateToken validates a 2FA token

func (*TwoFAProvider) VerifyBackupCode

func (tp *TwoFAProvider) VerifyBackupCode(ctx context.Context, userID, backupCode string) (*TwoFAVerification, error)

VerifyBackupCode verifies a backup code

func (*TwoFAProvider) VerifyCode

func (tp *TwoFAProvider) VerifyCode(ctx context.Context, secret, code string) (*TwoFAVerification, error)

VerifyCode verifies a 2FA code

type TwoFASecret

type TwoFASecret struct {
	Secret      string    `json:"secret"`
	QRCodeURL   string    `json:"qr_code_url"`
	BackupCodes []string  `json:"backup_codes"`
	CreatedAt   time.Time `json:"created_at"`
}

TwoFASecret represents a 2FA secret

type TwoFAVerification

type TwoFAVerification struct {
	Valid      bool   `json:"valid"`
	Message    string `json:"message"`
	BackupUsed bool   `json:"backup_used"`
}

TwoFAVerification represents 2FA verification result

Jump to

Keyboard shortcuts

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