Allow remember be duration to be customized via config
This commit is contained in:
parent
f47fbcf39a
commit
a0677f23e5
|
@ -12,9 +12,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
HTTP HTTPConfig `yaml:"http"`
|
HTTP HTTPConfig `yaml:"http"`
|
||||||
SMTP SMTPConfig `yaml:"smtp"`
|
SMTP SMTPConfig `yaml:"smtp"`
|
||||||
Hydra HydraConfig `yaml:"hydra"`
|
Hydra HydraConfig `yaml:"hydra"`
|
||||||
|
Session SessionConfig `yaml:"session"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFromFile retrieves the configuration from the given file
|
// 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"`
|
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 {
|
func NewDumpDefault() *Config {
|
||||||
config := NewDefault()
|
config := NewDefault()
|
||||||
return config
|
return config
|
||||||
|
@ -99,6 +105,10 @@ func NewDefault() *Config {
|
||||||
FakeSSLTermination: false,
|
FakeSSLTermination: false,
|
||||||
HTTPClientTimeout: time.Second * 30, //nolint: gomnb
|
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
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package route
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"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/hydra"
|
||||||
"forge.cadoles.com/wpetit/hydra-passwordless/internal/query"
|
"forge.cadoles.com/wpetit/hydra-passwordless/internal/query"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -14,6 +15,7 @@ import (
|
||||||
func handleVerification(w http.ResponseWriter, r *http.Request) {
|
func handleVerification(w http.ResponseWriter, r *http.Request) {
|
||||||
ctn := container.Must(r.Context())
|
ctn := container.Must(r.Context())
|
||||||
bus := cqrs.Must(ctn)
|
bus := cqrs.Must(ctn)
|
||||||
|
conf := config.Must(ctn)
|
||||||
|
|
||||||
token := r.URL.Query().Get("token")
|
token := r.URL.Query().Get("token")
|
||||||
if token == "" {
|
if token == "" {
|
||||||
|
@ -52,10 +54,15 @@ func handleVerification(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
hydr := hydra.Must(ctn)
|
hydr := hydra.Must(ctn)
|
||||||
|
|
||||||
|
rememberFor := conf.Session.DefaultDuration
|
||||||
|
if verifyUserData.RememberMe {
|
||||||
|
rememberFor = conf.Session.RememberMeDuration
|
||||||
|
}
|
||||||
|
|
||||||
accept := &hydra.AcceptLoginRequest{
|
accept := &hydra.AcceptLoginRequest{
|
||||||
Subject: verifyUserData.Email,
|
Subject: verifyUserData.Email,
|
||||||
Remember: verifyUserData.RememberMe,
|
Remember: verifyUserData.RememberMe,
|
||||||
RememberFor: 3600,
|
RememberFor: rememberFor,
|
||||||
Context: map[string]interface{}{
|
Context: map[string]interface{}{
|
||||||
"email": verifyUserData.Email,
|
"email": verifyUserData.Email,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue