Closed
Description
My parsing of token:
token, err := jwt.ParseWithClaims(tokenString, &accessToken{}, func(token *jwt.Token) (interface{}, error) {
return []byte(t.secretKey), nil
})
I took an example of how to distinguish between errors from the documentation
if err != nil {
if err.(*jwt.ValidationError).Errors&jwt.ValidationErrorExpired != 0 {
return &accessToken{
UserId: token.Claims.(*accessToken).UserId,
}, ErrTokenExpired
}
return nil, err
}
And here's what I noticed. This patch can fire even when the error is not a token expiration error.
if err.(*jwt.ValidationError).Errors&jwt.ValidationErrorExpired != 0 { ...
For example, this condition will work even on the "signature is invalid" error.
But only if the token has expired and it has been changed.
In other words:
Token | Condition |
---|---|
Token has been changed AND has not expired yet | doesn't work |
Token changed AND expired | It works |
But the condition should not work on an error like "signature is invalid"?
P.S
Can I compare errors like this?
if err.(*jwt.ValidationError).Errors&jwt.ValidationErrorExpired == jwt.ValidationErrorExpired { ...
Metadata
Metadata
Assignees
Labels
No labels