feature:调整jwt续期功能,保证新的token返回和一致性
This commit is contained in:
@@ -58,7 +58,6 @@ func JWTAuth() gin.HandlerFunc {
|
|||||||
// c.Abort()
|
// c.Abort()
|
||||||
//}
|
//}
|
||||||
c.Set("claims", claims)
|
c.Set("claims", claims)
|
||||||
c.Next()
|
|
||||||
if claims.ExpiresAt.Unix()-time.Now().Unix() < claims.BufferTime {
|
if claims.ExpiresAt.Unix()-time.Now().Unix() < claims.BufferTime {
|
||||||
dr, _ := utils.ParseDuration(global.GVA_CONFIG.JWT.ExpiresTime)
|
dr, _ := utils.ParseDuration(global.GVA_CONFIG.JWT.ExpiresTime)
|
||||||
claims.ExpiresAt = jwt.NewNumericDate(time.Now().Add(dr))
|
claims.ExpiresAt = jwt.NewNumericDate(time.Now().Add(dr))
|
||||||
@@ -78,5 +77,13 @@ func JWTAuth() gin.HandlerFunc {
|
|||||||
_ = jwtService.SetRedisJWT(newToken, newClaims.Username)
|
_ = jwtService.SetRedisJWT(newToken, newClaims.Username)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
c.Next()
|
||||||
|
|
||||||
|
if newToken, exists := c.Get("new-token"); exists {
|
||||||
|
c.Header("new-token", newToken.(string))
|
||||||
|
}
|
||||||
|
if newExpiresAt, exists := c.Get("new-expires-at"); exists {
|
||||||
|
c.Header("new-expires-at", newExpiresAt.(string))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user