mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
40fb13ba3c
* Add period TOPT config key to define the time in seconds each OTP is rotated * Add skew TOTP config to define how many keys either side of the current one should be considered valid * Add tests and set minimum values * Update config template * Use unix epoch for position calculation and Fix QR gen * This resolves the timer resetting improperly at the 0 seconds mark and allows for periods longer than 1 minute * Generate QR based on period * Fix OTP timer graphic
30 lines
796 B
Go
30 lines
796 B
Go
package validator
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/authelia/authelia/internal/configuration/schema"
|
|
)
|
|
|
|
const defaultTOTPIssuer = "Authelia"
|
|
const DefaultTOTPPeriod = 30
|
|
const DefaultTOTPSkew = 1
|
|
|
|
// ValidateTOTP validates and update TOTP configuration.
|
|
func ValidateTOTP(configuration *schema.TOTPConfiguration, validator *schema.StructValidator) {
|
|
if configuration.Issuer == "" {
|
|
configuration.Issuer = defaultTOTPIssuer
|
|
}
|
|
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"))
|
|
}
|
|
}
|