Closed Grabber closed 11 months ago
You should be able to first create a new parser with jwt.New
and jwt.WithLeeway
and then use that with request.WithParser
@oxisto, that you! Is the following snippet correct?
func VerifyJWToken(r *http.Request, secretKey []byte) (*jwt.RegisteredClaims, error) {
token, err := request.ParseFromRequest(r, request.AuthorizationHeaderExtractor, func(token *jwt.Token) (interface{}, error) {
return secretKey, nil
}, request.WithClaims(jwt.RegisteredClaims{}), request.WithParser(jwt.NewParser(jwt.WithLeeway(5 * time.Second))))
if err == nil {
if claims, ok := token.Claims.(*jwt.RegisteredClaims); ok && token.Valid {
return claims, nil
}
}
return nil, err
}
Is it possible to use WithLeeway with request.ParseFromRequest as with jwt.ParseWithClaims? -> https://github.com/golang-jwt/jwt/blob/v5.0.0/request/request.go