From af072b0b374cc48703b95021ae07cdd59e17e850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Du=C5=A1an=20Borov=C4=8Danin?= Date: Wed, 25 Dec 2024 23:44:30 +0100 Subject: [PATCH] MG-7 - Return an error in case of missing token type (#17) Signed-off-by: Dusan Borovcanin --- auth/jwt/tokenizer.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/auth/jwt/tokenizer.go b/auth/jwt/tokenizer.go index 201021407..df7e51f98 100644 --- a/auth/jwt/tokenizer.go +++ b/auth/jwt/tokenizer.go @@ -17,7 +17,10 @@ import ( ) var ( + // errInvalidIssuer is returned when the issuer is not magistrala.auth. errInvalidIssuer = errors.New("invalid token issuer value") + // errInvalidType is returned when there is no type field. + errInvalidType = errors.New("invalid token type") // errJWTExpiryKey is used to check if the token is expired. errJWTExpiryKey = errors.New(`"exp" not satisfied`) // ErrSignJWT indicates an error in signing jwt token. @@ -127,7 +130,7 @@ func toKey(tkn jwt.Token) (auth.Key, error) { tType, ok := tkn.Get(tokenType) if !ok { - return auth.Key{}, err + return auth.Key{}, errInvalidType } ktype, err := strconv.ParseInt(fmt.Sprintf("%v", tType), 10, 64) if err != nil {