Merge remote-tracking branch 'origin/v2.3.0release' into v2.3.0release

pull/351/head
Gordon 2 years ago
commit 1f8a965b7a

@ -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())
}
}
}

@ -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
}}
}
@ -100,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, "")
}
}

Loading…
Cancel
Save