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