Passport/pkg/security/factors.go

32 lines
565 B
Go
Raw Normal View History

2024-01-06 17:56:32 +00:00
package security
import (
"fmt"
"code.smartsheep.studio/hydrogen/passport/pkg/models"
"github.com/samber/lo"
)
func GetFactorCode(factor models.AuthFactor) error {
switch factor.Type {
case models.EmailPasswordFactor:
// TODO
return nil
default:
return fmt.Errorf("unsupported factor to get code")
}
}
func VerifyFactor(factor models.AuthFactor, code string) error {
switch factor.Type {
case models.PasswordAuthFactor:
return lo.Ternary(
VerifyPassword(code, factor.Secret),
nil,
fmt.Errorf("invalid password"),
)
}
return nil
}