Closed josegoval closed 2 years ago
1) Why *jwt.ValidationError
Actually what jwt.ParseWithClaims returns in case of an error is a pointer to jwt.ValidationError (e.g. one of the place we return error https://github.com/dgrijalva/jwt-go/blob/master/parser.go#L41)
The ValidationError itself is a structure that implements the error interface or simply speaking has Error method implemented so that satisfy the error interface (https://github.com/dgrijalva/jwt-go/blob/master/errors.go#L39)
Also, take a look at some boilerplate code, let's say best practice, here https://blog.golang.org/go1.13-errors, hope at helps.
(Maybe i mess it a bit, am new using this system)
Thank you a lot, seriously, A LOT. This make it quite clear.
So, the reason because the claims assertion requires a pointer to CustomTokenClaims
, is because, it is an interface, and it needs to be a pointer to use all the interface methods that StandardClaims
has, like func (c *StandardClaims) VerifyAudience(cmp string, req bool)
?
Thanks again.
Hello there. I haave this code:
but i dont understand why do I have to use jwt.ValidationError and CustomTokenClaims instead of normal value, as well as why "ParseWithClaims" recieves a reference of "CustomTokenClaims".
Thank you.