整理配置文件,jwt过期时间和缓冲时间支持1d2h3m4s事件类型 (#1218)
* feat: human duration * Update config.yaml * 调整配置文件结构 Co-authored-by: songzhibin97 <718428482@qq.com>
This commit is contained in:
@@ -4,9 +4,10 @@ import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
jwt "github.com/golang-jwt/jwt/v4"
|
||||
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
)
|
||||
|
||||
type JWT struct {
|
||||
@@ -27,13 +28,15 @@ func NewJWT() *JWT {
|
||||
}
|
||||
|
||||
func (j *JWT) CreateClaims(baseClaims request.BaseClaims) request.CustomClaims {
|
||||
bf, _ := ParseDuration(global.GVA_CONFIG.JWT.BufferTime)
|
||||
ep, _ := ParseDuration(global.GVA_CONFIG.JWT.ExpiresTime)
|
||||
claims := request.CustomClaims{
|
||||
BaseClaims: baseClaims,
|
||||
BufferTime: global.GVA_CONFIG.JWT.BufferTime, // 缓冲时间1天 缓冲时间内会获得新的token刷新令牌 此时一个用户会存在两个有效令牌 但是前端只留一个 另一个会丢失
|
||||
BufferTime: int64(bf), // 缓冲时间1天 缓冲时间内会获得新的token刷新令牌 此时一个用户会存在两个有效令牌 但是前端只留一个 另一个会丢失
|
||||
StandardClaims: jwt.StandardClaims{
|
||||
NotBefore: time.Now().Unix() - 1000, // 签名生效时间
|
||||
ExpiresAt: time.Now().Unix() + global.GVA_CONFIG.JWT.ExpiresTime, // 过期时间 7天 配置文件
|
||||
Issuer: global.GVA_CONFIG.JWT.Issuer, // 签名的发行者
|
||||
NotBefore: time.Now().Unix() - 1000, // 签名生效时间
|
||||
ExpiresAt: time.Now().Add(ep).Unix(), // 过期时间 7天 配置文件
|
||||
Issuer: global.GVA_CONFIG.JWT.Issuer, // 签名的发行者
|
||||
},
|
||||
}
|
||||
return claims
|
||||
|
Reference in New Issue
Block a user