/
auth.gen.go
85 lines (78 loc) · 3.53 KB
/
auth.gen.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package options
// This file is auto-generated.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
// Definitions file that controls how this file is generated:
// pkg/options/auth.yaml
import (
"time"
)
type (
AuthOpt struct {
LogEnabled bool `env:"AUTH_LOG_ENABLED"`
PasswordSecurity bool `env:"AUTH_PASSWORD_SECURITY"`
Secret string `env:"AUTH_JWT_SECRET"`
AccessTokenLifetime time.Duration `env:"AUTH_OAUTH2_ACCESS_TOKEN_LIFETIME"`
RefreshTokenLifetime time.Duration `env:"AUTH_OAUTH2_REFRESH_TOKEN_LIFETIME"`
Expiry time.Duration `env:"AUTH_JWT_EXPIRY"`
ExternalRedirectURL string `env:"AUTH_EXTERNAL_REDIRECT_URL"`
ExternalCookieSecret string `env:"AUTH_EXTERNAL_COOKIE_SECRET"`
BaseURL string `env:"AUTH_BASE_URL"`
SessionCookieName string `env:"AUTH_SESSION_COOKIE_NAME"`
SessionCookiePath string `env:"AUTH_SESSION_COOKIE_PATH"`
SessionCookieDomain string `env:"AUTH_SESSION_COOKIE_DOMAIN"`
SessionCookieSecure bool `env:"AUTH_SESSION_COOKIE_SECURE"`
SessionLifetime time.Duration `env:"AUTH_SESSION_LIFETIME"`
SessionPermLifetime time.Duration `env:"AUTH_SESSION_PERM_LIFETIME"`
GarbageCollectorInterval time.Duration `env:"AUTH_GARBAGE_COLLECTOR_INTERVAL"`
RequestRateLimit int `env:"AUTH_REQUEST_RATE_LIMIT"`
RequestRateWindowLength time.Duration `env:"AUTH_REQUEST_RATE_WINDOW_LENGTH"`
CsrfSecret string `env:"AUTH_CSRF_SECRET"`
CsrfEnabled bool `env:"AUTH_CSRF_ENABLED"`
CsrfFieldName string `env:"AUTH_CSRF_FIELD_NAME"`
CsrfCookieName string `env:"AUTH_CSRF_COOKIE_NAME"`
DefaultClient string `env:"AUTH_DEFAULT_CLIENT"`
AssetsPath string `env:"AUTH_ASSETS_PATH"`
DevelopmentMode bool `env:"AUTH_DEVELOPMENT_MODE"`
}
)
// Auth initializes and returns a AuthOpt with default values
func Auth() (o *AuthOpt) {
o = &AuthOpt{
PasswordSecurity: true,
Secret: getSecretFromEnv("jwt secret"),
AccessTokenLifetime: time.Hour * 2,
RefreshTokenLifetime: time.Hour * 24 * 3,
Expiry: time.Hour * 24 * 30,
ExternalRedirectURL: fullURL("/auth/external/{provider}/callback"),
ExternalCookieSecret: getSecretFromEnv("external cookie secret"),
BaseURL: fullURL("/auth"),
SessionCookieName: "session",
SessionCookiePath: pathPrefix("/auth"),
SessionCookieDomain: guessHostname(),
SessionCookieSecure: isSecure(),
SessionLifetime: 24 * time.Hour,
SessionPermLifetime: 360 * 24 * time.Hour,
GarbageCollectorInterval: 15 * time.Minute,
RequestRateLimit: 60,
RequestRateWindowLength: time.Minute,
CsrfSecret: getSecretFromEnv("csrf secret"),
CsrfEnabled: true,
CsrfFieldName: "same-site-authenticity-token",
CsrfCookieName: "same-site-authenticity-token",
DefaultClient: "corteza-webapp",
AssetsPath: "",
}
fill(o)
// Function that allows access to custom logic inside the parent function.
// The custom logic in the other file should be like:
// func (o *Auth) Defaults() {...}
func(o interface{}) {
if def, ok := o.(interface{ Defaults() }); ok {
def.Defaults()
}
}(o)
return
}