diff --git a/jwt.go b/jwt.go index 6920141..5a03731 100644 --- a/jwt.go +++ b/jwt.go @@ -46,27 +46,21 @@ func (j *ownJwt) Generate(signMethod jwt.SigningMethod, secret string, claims jw // Author : go_developer@163.com<白茶清欢> // // Date : 20:13 2023/2/11 -func (j *ownJwt) Validate(inputToken string, secret string, convert func(c jwt.Claims) error) error { - if nil == convert { - return errors.New("convert func is nil") - } +func (j *ownJwt) Validate(inputToken string, secret string, claims jwt.Claims) (jwt.Claims, error) { + var ( token *jwt.Token err error ) - if token, err = jwt.Parse(inputToken, func(tokenInfo *jwt.Token) (interface{}, error) { + if token, err = jwt.ParseWithClaims(inputToken, claims, func(tokenInfo *jwt.Token) (interface{}, error) { return []byte(secret), nil }); nil != err { - return errors.New("token parse fail : " + err.Error()) + return nil, errors.New("token parse fail : " + err.Error()) } if !token.Valid { - return errors.New("token is valid : " + err.Error()) + return nil, errors.New("token is valid : " + err.Error()) } - if nil != convert { - if err = convert(token.Claims); nil != err { - return err - } - } - return nil + + return token.Claims, nil }