2015-04-09 23:20:10 +03:00
|
|
|
package jwt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2023-02-21 16:32:25 +03:00
|
|
|
"strings"
|
2015-04-09 23:20:10 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2023-02-21 16:32:25 +03:00
|
|
|
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")
|
|
|
|
ErrTokenRequiredClaimMissing = errors.New("token is missing required claim")
|
|
|
|
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")
|
|
|
|
ErrTokenInvalidSubject = errors.New("token has invalid subject")
|
|
|
|
ErrTokenNotValidYet = errors.New("token is not valid yet")
|
|
|
|
ErrTokenInvalidId = errors.New("token has invalid id")
|
|
|
|
ErrTokenInvalidClaims = errors.New("token has invalid claims")
|
|
|
|
ErrInvalidType = errors.New("invalid type for claim")
|
2023-09-14 22:25:59 +03:00
|
|
|
ErrUnsupported = errors.New("operation is unsupported")
|
2015-04-09 23:20:10 +03:00
|
|
|
)
|
|
|
|
|
2023-02-21 16:32:25 +03:00
|
|
|
// joinedError is an error type that works similar to what [errors.Join]
|
|
|
|
// produces, with the exception that it has a nice error string; mainly its
|
|
|
|
// error messages are concatenated using a comma, rather than a newline.
|
|
|
|
type joinedError struct {
|
|
|
|
errs []error
|
2015-04-09 23:20:10 +03:00
|
|
|
}
|
|
|
|
|
2023-02-21 16:32:25 +03:00
|
|
|
func (je joinedError) Error() string {
|
|
|
|
msg := []string{}
|
|
|
|
for _, err := range je.errs {
|
|
|
|
msg = append(msg, err.Error())
|
2015-04-09 23:20:10 +03:00
|
|
|
}
|
2021-11-15 17:25:32 +03:00
|
|
|
|
2023-02-21 16:32:25 +03:00
|
|
|
return strings.Join(msg, ", ")
|
2015-04-09 23:20:10 +03:00
|
|
|
}
|
2022-01-20 00:55:19 +03:00
|
|
|
|
2023-02-21 16:32:25 +03:00
|
|
|
// joinErrors joins together multiple errors. Useful for scenarios where
|
|
|
|
// multiple errors next to each other occur, e.g., in claims validation.
|
|
|
|
func joinErrors(errs ...error) error {
|
|
|
|
return &joinedError{
|
|
|
|
errs: errs,
|
2022-01-20 00:55:19 +03:00
|
|
|
}
|
|
|
|
}
|