-
Notifications
You must be signed in to change notification settings - Fork 0
/
config_validate.go
56 lines (45 loc) · 1.51 KB
/
config_validate.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
)
func (config *Schema) validate() (err error) {
if config.AutheliaURL == nil {
return fmt.Errorf("error validating configuration: the 'authelia_url' value is required")
}
if len(config.Storage) == 0 {
return fmt.Errorf("error validating configuration: the 'storage' value is required")
}
return nil
}
const (
errFmtRequiredOptionOAuth2Bearer = "error validating configuration: oauth2: bearer: the '%s' value is required"
errFmtNotKnownOptionOAuth2Bearer = "error validating configuration: oauth2: bearer: the '%s' value of '%s' is not known"
)
func (config *SchemaOAuth2Bearer) validate() (err error) {
if len(config.ID) == 0 {
return fmt.Errorf(errFmtRequiredOptionOAuth2Bearer, strID)
}
if len(config.Secret) == 0 {
return fmt.Errorf(errFmtRequiredOptionOAuth2Bearer, strSecret)
}
if len(config.Scope) == 0 {
return fmt.Errorf(errFmtRequiredOptionOAuth2Bearer, strScope)
}
switch config.GrantType {
case "":
return fmt.Errorf(errFmtRequiredOptionOAuth2Bearer, strGrantType)
case strAuthorizationCode, strRefreshToken, strClientCredentials:
break
default:
return fmt.Errorf(errFmtNotKnownOptionOAuth2Bearer, strGrantType, config.GrantType)
}
switch config.TokenEndpointAuthMethod {
case "":
return fmt.Errorf(errFmtRequiredOptionOAuth2Bearer, strTokenEndpointAuthMethod)
case strClientSecretPost, strClientSecretBasic:
break
default:
return fmt.Errorf(errFmtNotKnownOptionOAuth2Bearer, strTokenEndpointAuthMethod, config.TokenEndpointAuthMethod)
}
return nil
}