summaryrefslogtreecommitdiff
path: root/internal/configuration/validator/webauthn.go
blob: 47aaa27048509b9835496157627d6b3fb2c15fa9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package validator

import (
	"fmt"
	"strings"

	"github.com/authelia/authelia/v4/internal/configuration/schema"
	"github.com/authelia/authelia/v4/internal/utils"
)

// ValidateWebauthn validates and update Webauthn configuration.
func ValidateWebauthn(config *schema.Configuration, validator *schema.StructValidator) {
	if config.Webauthn.DisplayName == "" {
		config.Webauthn.DisplayName = schema.DefaultWebauthnConfiguration.DisplayName
	}

	if config.Webauthn.Timeout <= 0 {
		config.Webauthn.Timeout = schema.DefaultWebauthnConfiguration.Timeout
	}

	switch {
	case config.Webauthn.ConveyancePreference == "":
		config.Webauthn.ConveyancePreference = schema.DefaultWebauthnConfiguration.ConveyancePreference
	case !utils.IsStringInSlice(string(config.Webauthn.ConveyancePreference), validWebauthnConveyancePreferences):
		validator.Push(fmt.Errorf(errFmtWebauthnConveyancePreference, strings.Join(validWebauthnConveyancePreferences, "', '"), config.Webauthn.ConveyancePreference))
	}

	switch {
	case config.Webauthn.UserVerification == "":
		config.Webauthn.UserVerification = schema.DefaultWebauthnConfiguration.UserVerification
	case !utils.IsStringInSlice(string(config.Webauthn.UserVerification), validWebauthnUserVerificationRequirement):
		validator.Push(fmt.Errorf(errFmtWebauthnUserVerification, config.Webauthn.UserVerification))
	}
}