From b23680f9132bc9b5abf2583a68a9e2475fcd0424 Mon Sep 17 00:00:00 2001 From: JSker9 <31596045+MemoryShadow@users.noreply.github.com> Date: Sun, 2 Mar 2025 15:37:46 +0800 Subject: [PATCH] feat: add configurable JWT timeout setting (#1014) --- cmd/dashboard/controller/jwt.go | 4 ++-- model/config.go | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/dashboard/controller/jwt.go b/cmd/dashboard/controller/jwt.go index 5323b958a5..476b59469c 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 6c5486ccdf..76d7bf6a70 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 {