Skip to content

Commit

Permalink
feat: add configurable JWT timeout setting (#1014)
Browse files Browse the repository at this point in the history
  • Loading branch information
MemoryShadow authored Mar 2, 2025
1 parent 5c8cc75 commit b23680f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/dashboard/controller/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),

Expand Down
6 changes: 6 additions & 0 deletions model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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不打码

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b23680f

Please sign in to comment.