Skip to content

Commit

Permalink
返回签名,便于做二次验证
Browse files Browse the repository at this point in the history
  • Loading branch information
gowater committed Apr 7, 2023
1 parent af9e9db commit 66bda16
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,22 @@ func SetAuthToken(uniqueUser, privateKey string, expire time.Duration) (tokenStr
return tokenString, nil
}

func ParseAndValid(req *http.Request, privateKey string) (uniqueUser string, err error) {
func ParseAndValid(req *http.Request, privateKey string) (uniqueUser, signature string, err error) {
token, err := request.ParseFromRequest(req, request.AuthorizationHeaderExtractor, func(t *jwt.Token) (interface{}, error) {
return []byte(privateKey), nil
}, request.WithClaims(&jwt.RegisteredClaims{}))
if err != nil {
return "", err
return "", "", err
}

if !token.Valid {
return "", jwt.ErrTokenSignatureInvalid
return "", "", jwt.ErrTokenSignatureInvalid
}

claims, ok := token.Claims.(*jwt.RegisteredClaims)
if !ok {
return "", jwt.ErrTokenInvalidClaims
return "", "", jwt.ErrTokenInvalidClaims
}

return claims.Issuer, nil
return claims.Issuer, token.Signature, nil
}

0 comments on commit 66bda16

Please sign in to comment.