2019-04-25 04:52:08 +07:00
|
|
|
package validator
|
|
|
|
|
|
|
|
import (
|
2020-03-25 08:48:20 +07:00
|
|
|
"fmt"
|
2020-04-05 19:37:21 +07:00
|
|
|
|
2021-08-11 08:04:35 +07:00
|
|
|
"github.com/authelia/authelia/v4/internal/configuration/schema"
|
2019-04-25 04:52:08 +07:00
|
|
|
)
|
|
|
|
|
|
|
|
// ValidateTOTP validates and update TOTP configuration.
|
|
|
|
func ValidateTOTP(configuration *schema.TOTPConfiguration, validator *schema.StructValidator) {
|
|
|
|
if configuration.Issuer == "" {
|
2020-04-05 19:37:21 +07:00
|
|
|
configuration.Issuer = schema.DefaultTOTPConfiguration.Issuer
|
2019-04-25 04:52:08 +07:00
|
|
|
}
|
2020-05-06 02:35:32 +07:00
|
|
|
|
2020-03-25 08:48:20 +07:00
|
|
|
if configuration.Period == 0 {
|
2020-04-05 19:37:21 +07:00
|
|
|
configuration.Period = schema.DefaultTOTPConfiguration.Period
|
2020-03-25 08:48:20 +07:00
|
|
|
} else if configuration.Period < 0 {
|
|
|
|
validator.Push(fmt.Errorf("TOTP Period must be 1 or more"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if configuration.Skew == nil {
|
2020-04-05 19:37:21 +07:00
|
|
|
configuration.Skew = schema.DefaultTOTPConfiguration.Skew
|
2020-03-25 08:48:20 +07:00
|
|
|
} else if *configuration.Skew < 0 {
|
|
|
|
validator.Push(fmt.Errorf("TOTP Skew must be 0 or more"))
|
|
|
|
}
|
2019-04-25 04:52:08 +07:00
|
|
|
}
|