1 package jwt 2 3 // Validation provides a backwards compatible error definition 4 // from `jwt-go` to `go-jose`. 5 // The sourcecode was taken from https://github.com/dgrijalva/jwt-go/blob/master/errors.go 6 // 7 // > The errors that might occur when parsing and validating a token 8 const ( 9 ValidationErrorMalformed uint32 = 1 << iota // Token is malformed 10 ValidationErrorUnverifiable // Token could not be verified because of signing problems 11 ValidationErrorSignatureInvalid // Signature validation failed 12 13 // Standard Claim validation errors 14 ValidationErrorAudience // AUD validation failed 15 ValidationErrorExpired // EXP validation failed 16 ValidationErrorIssuedAt // IAT validation failed 17 ValidationErrorIssuer // ISS validation failed 18 ValidationErrorNotValidYet // NBF validation failed 19 ValidationErrorId // JTI validation failed 20 ValidationErrorClaimsInvalid // Generic claims validation error 21 ) 22 23 // The error from Parse if token is not valid 24 type ValidationError struct { 25 Inner error // stores the error returned by external dependencies, i.e.: KeyFunc 26 Errors uint32 // bitfield. see ValidationError... constants 27 text string // errors that do not have a valid error just have text 28 } 29 30 // Validation error is an error type 31 func (e ValidationError) Error() string { 32 if e.Inner != nil { 33 return e.Inner.Error() 34 } else if e.text != "" { 35 return e.text 36 } else { 37 return "token is invalid" 38 } 39 } 40 41 // No errors 42 func (e *ValidationError) valid() bool { 43 return e.Errors == 0 44 } 45 46 func (e *ValidationError) Has(verr uint32) bool { 47 return (e.Errors & verr) != 0 48 } 49