Allow remember be duration to be customized via config

This commit is contained in:
wpetit 2020-09-08 11:38:38 +02:00
parent f47fbcf39a
commit a0677f23e5
2 changed files with 21 additions and 4 deletions

View File

@ -15,6 +15,7 @@ type Config struct {
HTTP HTTPConfig `yaml:"http"`
SMTP SMTPConfig `yaml:"smtp"`
Hydra HydraConfig `yaml:"hydra"`
Session SessionConfig `yaml:"session"`
}
// NewFromFile retrieves the configuration from the given file
@ -67,6 +68,11 @@ type HydraConfig struct {
HTTPClientTimeout time.Duration `yaml:"httpClientTimeout" env:"HYDRA_HTTP_CLIENT_TIMEOUT"`
}
type SessionConfig struct {
DefaultDuration int `yaml:"defaultDuration" env:"HYDRA_SESSION_DEFAULT_DURATION"`
RememberMeDuration int `yaml:"rememberMeDuration" env:"HYDRA_SESSION_REMEMBER_ME_DURATION"`
}
func NewDumpDefault() *Config {
config := NewDefault()
return config
@ -99,6 +105,10 @@ func NewDefault() *Config {
FakeSSLTermination: false,
HTTPClientTimeout: time.Second * 30, //nolint: gomnb
},
Session: SessionConfig{
DefaultDuration: int((time.Hour * 1).Seconds()), // 1 hour
RememberMeDuration: int((time.Hour * 24 * 30).Seconds()), // 30 days
},
}
}

View File

@ -3,6 +3,7 @@ package route
import (
"net/http"
"forge.cadoles.com/wpetit/hydra-passwordless/internal/config"
"forge.cadoles.com/wpetit/hydra-passwordless/internal/hydra"
"forge.cadoles.com/wpetit/hydra-passwordless/internal/query"
"github.com/pkg/errors"
@ -14,6 +15,7 @@ import (
func handleVerification(w http.ResponseWriter, r *http.Request) {
ctn := container.Must(r.Context())
bus := cqrs.Must(ctn)
conf := config.Must(ctn)
token := r.URL.Query().Get("token")
if token == "" {
@ -52,10 +54,15 @@ func handleVerification(w http.ResponseWriter, r *http.Request) {
hydr := hydra.Must(ctn)
rememberFor := conf.Session.DefaultDuration
if verifyUserData.RememberMe {
rememberFor = conf.Session.RememberMeDuration
}
accept := &hydra.AcceptLoginRequest{
Subject: verifyUserData.Email,
Remember: verifyUserData.RememberMe,
RememberFor: 3600,
RememberFor: rememberFor,
Context: map[string]interface{}{
"email": verifyUserData.Email,
},