2019-04-24 21:52:08 +00:00
|
|
|
package validator
|
|
|
|
|
|
|
|
import (
|
2020-03-25 01:48:20 +00:00
|
|
|
"fmt"
|
2019-12-24 02:14:52 +00:00
|
|
|
"github.com/authelia/authelia/internal/configuration/schema"
|
2019-04-24 21:52:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const defaultTOTPIssuer = "Authelia"
|
2020-03-25 01:48:20 +00:00
|
|
|
const DefaultTOTPPeriod = 30
|
|
|
|
const DefaultTOTPSkew = 1
|
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 == "" {
|
|
|
|
configuration.Issuer = defaultTOTPIssuer
|
|
|
|
}
|
2020-03-25 01:48:20 +00:00
|
|
|
if configuration.Period == 0 {
|
|
|
|
configuration.Period = DefaultTOTPPeriod
|
|
|
|
} else if configuration.Period < 0 {
|
|
|
|
validator.Push(fmt.Errorf("TOTP Period must be 1 or more"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if configuration.Skew == nil {
|
|
|
|
var skew = DefaultTOTPSkew
|
|
|
|
configuration.Skew = &skew
|
|
|
|
} else if *configuration.Skew < 0 {
|
|
|
|
validator.Push(fmt.Errorf("TOTP Skew must be 0 or more"))
|
|
|
|
}
|
2019-04-24 21:52:08 +00:00
|
|
|
}
|