func ValidateJWTToken(tokenString string, addr hash.Hash, key bmcrypto.PubKey) (*jwt.Token, error) {
	logrus.Tracef("validating JWT token")

	// Just return the key from the token
	kf := func(token *jwt.Token) (interface{}, error) {
		return key.K, nil
	}

	claims := &jwt.StandardClaims{}
	token, err := jwt.ParseWithClaims(tokenString, claims, kf)
	if err != nil {
		if ve, ok := err.(*jwt.ValidationError); ok {
			// When timing is off, return a separate message, as we can pass this to the caller
			if ve.Errors&(jwt.ValidationErrorExpired|jwt.ValidationErrorNotValidYet) != 0 {
				logrus.Trace("auth: jwt: token time is not valid")
				return nil, ErrTokenTimeNotValid
			}
		}

		logrus.Trace("auth: jwt: ", err)
		return nil, err
	}

	// Make sure the signature method of the JWT matches our public key
	if !key.Type.JWTHasValidSignMethod(token) {
		logrus.Tracef("auth: jwt: " + invalidSigningMethod)
		return nil, ErrInvalidSigningMethod
	}

	// It should be a valid token
	if !token.Valid {
		logrus.Trace("auth: jwt: token not valid")
		return nil, ErrTokenNotValid
	}

	// The standard claims should be valid
	err = token.Claims.Valid()
	if err != nil {
		logrus.Trace("auth: jwt: ", err)
		return nil, err
	}

	// Check subject explicitly
	res := subtle.ConstantTimeCompare([]byte(token.Claims.(*jwt.StandardClaims).Subject), []byte(addr.String()))
	if res == 0 {
		logrus.Tracef("auth: jwt: subject does not match")
		return nil, ErrSubjectNotValid
	}

	logrus.Trace("auth: jwt: token is valid")
	return token, nil
}
// ValidateJWTToken validates a JWT token with the given public key and address
ValidateJWTToken validates a JWT token with the given public key and address
// ValidateJWTToken validates a JWT token with the given public key and address
func ValidateJWTToken(tokenString string, addr hash.Hash, key bmcrypto.PubKey) (*jwt.Token, error) {
	logrus.Tracef("validating JWT token")
	kf := func(token *jwt.Token) (interface{}, error) {
		return key.K, nil
	}
	claims := &jwt.StandardClaims{}
	token, err := jwt.ParseWithClaims(tokenString, claims, kf)
	if err != nil {
		if ve, ok := err.(*jwt.ValidationError); ok {
			if ve.Errors&(jwt.ValidationErrorExpired|jwt.ValidationErrorNotValidYet) != 0 {
				logrus.Trace("auth: jwt: token time is not valid")
				return nil, ErrTokenTimeNotValid
			}
		}
		logrus.Trace("auth: jwt: ", err)
		return nil, err
	}
	if !key.Type.JWTHasValidSignMethod(token) {
		logrus.Tracef("auth: jwt: " + invalidSigningMethod)
		return nil, ErrInvalidSigningMethod
	}
	if !token.Valid {
		logrus.Trace("auth: jwt: token not valid")
		return nil, ErrTokenNotValid
	}
	err = token.Claims.Valid()
	if err != nil {
		logrus.Trace("auth: jwt: ", err)
		return nil, err
	}
	res := subtle.ConstantTimeCompare([]byte(token.Claims.(*jwt.StandardClaims).Subject), []byte(addr.String()))
	if res == 0 {
		logrus.Tracef("auth: jwt: subject does not match")
		return nil, ErrSubjectNotValid
	}
	logrus.Trace("auth: jwt: token is valid")
	return token, nil
}
func ValidateJWTToken ( tokenString string , addr hash . Hash , key bmcrypto . PubKey ) ( * jwt . Token , error ) { logrus . Tracef ( " " ) kf := func ( token * jwt . Token ) ( interface { } , error ) { return key . K , nil } claims := & jwt . StandardClaims { } token , err := jwt . ParseWithClaims ( tokenString , claims , kf ) if err != nil { if ve , ok := err . ( * jwt . ValidationError ) ; ok { if ve . Errors & ( jwt . ValidationErrorExpired | jwt . ValidationErrorNotValidYet ) != 0 { logrus . Trace ( " " ) return nil , ErrTokenTimeNotValid } } logrus . Trace ( " " , err ) return nil , err } if ! key . Type . JWTHasValidSignMethod ( token ) { logrus . Tracef ( " " + invalidSigningMethod ) return nil , ErrInvalidSigningMethod } if ! token . Valid { logrus . Trace ( " " ) return nil , ErrTokenNotValid } err = token . Claims . Valid ( ) if err != nil { logrus . Trace ( " " , err ) return nil , err } res := subtle . ConstantTimeCompare ( [ ] byte ( token . Claims . ( * jwt . StandardClaims ) . Subject ) , [ ] byte ( addr . String ( ) ) ) if res == 0 { logrus . Tracef ( " " ) return nil , ErrSubjectNotValid } logrus . Trace ( " " ) return token , nil }
ValidateJWTToken validates a JWT token with the given public key and address
ValidateJWTToken validates a JWT token with the given public key and address
// Just return the key from the token // When timing is off, return a separate message, as we can pass this to the caller // Make sure the signature method of the JWT matches our public key // It should be a valid token // The standard claims should be valid // Check subject explicitly