2023-11-16 13:00:54 +00:00
|
|
|
package providers
|
|
|
|
|
|
|
|
import "context"
|
|
|
|
|
|
|
|
// AuthenticatorConfig defines authenticator config
|
|
|
|
type AuthenticatorConfig struct {
|
|
|
|
// ScannerImage is the base64 of QR code image
|
|
|
|
ScannerImage string
|
|
|
|
// Secrets is the secret key
|
|
|
|
Secret string
|
2023-12-01 08:30:01 +00:00
|
|
|
// RecoveryCode is the list of recovery codes
|
2023-11-16 13:00:54 +00:00
|
|
|
RecoveryCodes []string
|
2023-12-01 08:30:01 +00:00
|
|
|
// RecoveryCodeMap is the map of recovery codes
|
|
|
|
RecoveryCodeMap map[string]bool
|
2023-11-16 13:00:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Provider defines authenticators provider
|
|
|
|
type Provider interface {
|
|
|
|
// Generate totp: to generate totp, store secret into db and returns base64 of QR code image
|
|
|
|
Generate(ctx context.Context, id string) (*AuthenticatorConfig, error)
|
|
|
|
// Validate totp: user passcode with secret stored in our db
|
2023-12-03 03:33:22 +00:00
|
|
|
Validate(ctx context.Context, passcode string, userID string) (bool, error)
|
|
|
|
// ValidateRecoveryCode totp: allows user to validate using recovery code incase if they lost their device
|
|
|
|
ValidateRecoveryCode(ctx context.Context, recoveryCode, userID string) (bool, error)
|
2023-11-16 13:00:54 +00:00
|
|
|
}
|