diff --git a/cmd/dashboard/controller/jwt.go b/cmd/dashboard/controller/jwt.go index 5323b95..476b594 100644 --- a/cmd/dashboard/controller/jwt.go +++ b/cmd/dashboard/controller/jwt.go @@ -22,8 +22,8 @@ func initParams() *jwt.GinJWTMiddleware { Key: []byte(singleton.Conf.JWTSecretKey), CookieName: "nz-jwt", SendCookie: true, - Timeout: time.Hour, - MaxRefresh: time.Hour, + Timeout: time.Hour * time.Duration(singleton.Conf.JWTTimeout), + MaxRefresh: time.Hour * time.Duration(singleton.Conf.JWTTimeout), IdentityKey: model.CtxKeyAuthorizedUser, PayloadFunc: payloadFunc(), diff --git a/model/config.go b/model/config.go index 6c5486c..76d7bf6 100644 --- a/model/config.go +++ b/model/config.go @@ -40,6 +40,7 @@ type ConfigDashboard struct { Location string `koanf:"location" json:"location,omitempty"` // 时区,默认为 Asia/Shanghai ForceAuth bool `koanf:"force_auth" json:"force_auth,omitempty"` // 强制要求认证 AgentSecretKey string `koanf:"agent_secret_key" json:"agent_secret_key,omitempty"` + JWTTimeout int `mapstructure:"jwt_timeout" json:"jwt_timeout,omitempty"` // JWT token过期时间(小时) EnablePlainIPInNotification bool `koanf:"enable_plain_ip_in_notification" json:"enable_plain_ip_in_notification,omitempty"` // 通知信息IP不打码 @@ -144,6 +145,11 @@ func (c *Config) Read(path string, frontendTemplates []FrontendTemplate) error { } } + // Add JWTTimeout default check + if c.JWTTimeout == 0 { + c.JWTTimeout = 1 + } + if c.AgentSecretKey == "" { c.AgentSecretKey, err = utils.GenerateRandomString(32) if err != nil {