Source File
errors.go
Belonging Package
github.com/golang-jwt/jwt/v4
package jwtimport ()// Error constantsvar (ErrInvalidKey = errors.New("key is invalid")ErrInvalidKeyType = errors.New("key is of invalid type")ErrHashUnavailable = errors.New("the requested hash function is unavailable")ErrTokenMalformed = errors.New("token is malformed")ErrTokenUnverifiable = errors.New("token is unverifiable")ErrTokenSignatureInvalid = errors.New("token signature is invalid")ErrTokenInvalidAudience = errors.New("token has invalid audience")ErrTokenExpired = errors.New("token is expired")ErrTokenUsedBeforeIssued = errors.New("token used before issued")ErrTokenInvalidIssuer = errors.New("token has invalid issuer")ErrTokenNotValidYet = errors.New("token is not valid yet")ErrTokenInvalidId = errors.New("token has invalid id")ErrTokenInvalidClaims = errors.New("token has invalid claims"))// The errors that might occur when parsing and validating a tokenconst (ValidationErrorMalformed uint32 = 1 << iota // Token is malformedValidationErrorUnverifiable // Token could not be verified because of signing problemsValidationErrorSignatureInvalid // Signature validation failed// Standard Claim validation errorsValidationErrorAudience // AUD validation failedValidationErrorExpired // EXP validation failedValidationErrorIssuedAt // IAT validation failedValidationErrorIssuer // ISS validation failedValidationErrorNotValidYet // NBF validation failedValidationErrorId // JTI validation failedValidationErrorClaimsInvalid // Generic claims validation error)// NewValidationError is a helper for constructing a ValidationError with a string error messagefunc ( string, uint32) *ValidationError {return &ValidationError{text: ,Errors: ,}}// ValidationError represents an error from Parse if token is not validtype ValidationError struct {Inner error // stores the error returned by external dependencies, i.e.: KeyFuncErrors uint32 // bitfield. see ValidationError... constantstext string // errors that do not have a valid error just have text}// Error is the implementation of the err interface.func ( ValidationError) () string {if .Inner != nil {return .Inner.Error()} else if .text != "" {return .text} else {return "token is invalid"}}// Unwrap gives errors.Is and errors.As access to the inner error.func ( *ValidationError) () error {return .Inner}// No errorsfunc ( *ValidationError) () bool {return .Errors == 0}// Is checks if this ValidationError is of the supplied error. We are first checking for the exact error message// by comparing the inner error message. If that fails, we compare using the error flags. This way we can use// custom error messages (mainly for backwards compatability) and still leverage errors.Is using the global error variables.func ( *ValidationError) ( error) bool {// Check, if our inner error is a direct matchif errors.Is(errors.Unwrap(), ) {return true}// Otherwise, we need to match using our error flagsswitch {case ErrTokenMalformed:return .Errors&ValidationErrorMalformed != 0case ErrTokenUnverifiable:return .Errors&ValidationErrorUnverifiable != 0case ErrTokenSignatureInvalid:return .Errors&ValidationErrorSignatureInvalid != 0case ErrTokenInvalidAudience:return .Errors&ValidationErrorAudience != 0case ErrTokenExpired:return .Errors&ValidationErrorExpired != 0case ErrTokenUsedBeforeIssued:return .Errors&ValidationErrorIssuedAt != 0case ErrTokenInvalidIssuer:return .Errors&ValidationErrorIssuer != 0case ErrTokenNotValidYet:return .Errors&ValidationErrorNotValidYet != 0case ErrTokenInvalidId:return .Errors&ValidationErrorId != 0case ErrTokenInvalidClaims:return .Errors&ValidationErrorClaimsInvalid != 0}return false}
![]() |
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |