From 073b6d200a751a4f9ea0c4a46226f4e850dbb2d9 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Mon, 15 Aug 2022 15:40:36 +0800 Subject: [PATCH 1/2] Set the token activity time to five minutes ago --- pkg/common/config/config.go | 3 +-- pkg/common/token_verify/jwt_token.go | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index 53082d375..bee127d25 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -524,7 +524,7 @@ func init() { if err != nil { bytes, err = ioutil.ReadFile(filepath.Join(Root, "config", "config.yaml")) if err != nil { - panic(err.Error()) + panic(err.Error() + " config: " + filepath.Join(cfgName, "config", "config.yaml")) } } else { Root = cfgName @@ -541,5 +541,4 @@ func init() { panic(err.Error()) } } - } diff --git a/pkg/common/token_verify/jwt_token.go b/pkg/common/token_verify/jwt_token.go index 3f9e64fdf..04379364f 100644 --- a/pkg/common/token_verify/jwt_token.go +++ b/pkg/common/token_verify/jwt_token.go @@ -28,13 +28,14 @@ type Claims struct { func BuildClaims(uid, platform string, ttl int64) Claims { now := time.Now() + before := now.Add(-time.Minute * 5) return Claims{ UID: uid, Platform: platform, RegisteredClaims: jwt.RegisteredClaims{ ExpiresAt: jwt.NewNumericDate(now.Add(time.Duration(ttl*24) * time.Hour)), //Expiration time IssuedAt: jwt.NewNumericDate(now), //Issuing time - NotBefore: jwt.NewNumericDate(now), //Begin Effective time + NotBefore: jwt.NewNumericDate(before), //Begin Effective time }} } From 5e3a3c61f32045f5f1c3fd816c6609d137c5e5f4 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Mon, 15 Aug 2022 15:47:26 +0800 Subject: [PATCH 2/2] Set the token activity time to five minutes ago --- pkg/common/token_verify/jwt_token.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/pkg/common/token_verify/jwt_token.go b/pkg/common/token_verify/jwt_token.go index 04379364f..20942faf2 100644 --- a/pkg/common/token_verify/jwt_token.go +++ b/pkg/common/token_verify/jwt_token.go @@ -101,25 +101,22 @@ func GetClaimFromToken(tokensString string) (*Claims, error) { if err != nil { if ve, ok := err.(*jwt.ValidationError); ok { if ve.Errors&jwt.ValidationErrorMalformed != 0 { - return nil, constant.ErrTokenMalformed + return nil, utils.Wrap(constant.ErrTokenMalformed, "") } else if ve.Errors&jwt.ValidationErrorExpired != 0 { - return nil, constant.ErrTokenExpired + return nil, utils.Wrap(constant.ErrTokenExpired, "") } else if ve.Errors&jwt.ValidationErrorNotValidYet != 0 { - log.Error("", "ParseToken failed, ", err.Error(), token) - return nil, nil - // return nil, constant.ErrTokenNotValidYet + return nil, utils.Wrap(constant.ErrTokenNotValidYet, "") } else { - return nil, constant.ErrTokenUnknown + return nil, utils.Wrap(constant.ErrTokenUnknown, "") } } else { - return nil, constant.ErrTokenNotValidYet + return nil, utils.Wrap(constant.ErrTokenNotValidYet, "") } } else { if claims, ok := token.Claims.(*Claims); ok && token.Valid { - //log.NewDebug("", claims.UID, claims.Platform) return claims, nil } - return nil, constant.ErrTokenNotValidYet + return nil, utils.Wrap(constant.ErrTokenNotValidYet, "") } }