feat: add configurable JWT timeout setting (#1014)

This commit is contained in:
JSker9 2025-03-02 15:37:46 +08:00 committed by GitHub
parent 5c8cc75523
commit b23680f913
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 2 deletions

View File

@ -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(),

View File

@ -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 {