mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-11-27 12:39:01 +08:00
fix: 修改 jwt 超时时间为 1 小时 (#437)
This commit is contained in:
parent
cbe9c83515
commit
4a1aa84fa8
@ -118,7 +118,7 @@ func (u *AuthService) generateSession(c *gin.Context, name, authMethod string) (
|
||||
j := jwt.NewJWT()
|
||||
claims := j.CreateClaims(jwt.BaseClaims{
|
||||
Name: name,
|
||||
}, lifeTime)
|
||||
})
|
||||
token, err := j.CreateToken(claims)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -6,7 +6,7 @@ const (
|
||||
|
||||
AuthMethodJWT = "jwt"
|
||||
JWTHeaderName = "Authorization"
|
||||
JWTBufferTime = 86400
|
||||
JWTBufferTime = 3600
|
||||
JWTIssuer = "1Panel"
|
||||
|
||||
PasswordExpiredName = "expired"
|
||||
|
@ -1,15 +1,9 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
||||
"github.com/1Panel-dev/1Panel/backend/app/repo"
|
||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||
"github.com/1Panel-dev/1Panel/backend/global"
|
||||
jwtUtils "github.com/1Panel-dev/1Panel/backend/utils/jwt"
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
@ -27,15 +21,6 @@ func JwtAuth() gin.HandlerFunc {
|
||||
helper.ErrorWithDetail(c, constant.CodeErrUnauthorized, constant.ErrTypeInternalServer, err)
|
||||
return
|
||||
}
|
||||
if claims.ExpiresAt.Unix()-time.Now().Unix() < claims.BufferTime {
|
||||
settingRepo := repo.NewISettingRepo()
|
||||
setting, err := settingRepo.Get(settingRepo.WithByKey("SessionTimeout"))
|
||||
if err != nil {
|
||||
global.LOG.Errorf("create operation record failed, err: %v", err)
|
||||
}
|
||||
lifeTime, _ := strconv.Atoi(setting.Value)
|
||||
claims.ExpiresAt = jwt.NewNumericDate(time.Now().Add(time.Second * time.Duration(lifeTime)))
|
||||
}
|
||||
c.Set("claims", claims)
|
||||
c.Set("authMethod", constant.AuthMethodJWT)
|
||||
c.Next()
|
||||
|
@ -38,12 +38,12 @@ func NewJWT() *JWT {
|
||||
}
|
||||
}
|
||||
|
||||
func (j *JWT) CreateClaims(baseClaims BaseClaims, ttl int) CustomClaims {
|
||||
func (j *JWT) CreateClaims(baseClaims BaseClaims) CustomClaims {
|
||||
claims := CustomClaims{
|
||||
BaseClaims: baseClaims,
|
||||
BufferTime: constant.JWTBufferTime,
|
||||
RegisteredClaims: jwt.RegisteredClaims{
|
||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Second * time.Duration(ttl))),
|
||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Second * time.Duration(constant.JWTBufferTime))),
|
||||
Issuer: constant.JWTIssuer,
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user