Skip to content

Bug: Nil error returned in case of token type missing #7

@alingse

Description

@alingse

What were you trying to achieve?

https://github.com/absmach/magistrala/blob/main/auth/jwt/tokenizer.go#L130

func toKey(tkn jwt.Token) (auth.Key, error) {
	data, err := json.Marshal(tkn.PrivateClaims())
	if err != nil {
		return auth.Key{}, errors.Wrap(ErrJSONHandle, err)
	}
	var key auth.Key
	if err := json.Unmarshal(data, &key); err != nil {
		return auth.Key{}, errors.Wrap(ErrJSONHandle, err)
	}

	tType, ok := tkn.Get(tokenType)
	if !ok {
		return auth.Key{}, err // which the err is nil
	}

What are the expected results?

define a new err like errInvalidToken

in https://github.com/absmach/magistrala/blob/main/auth/jwt/tokenizer.go#L19-L28

and return

What are the received results?

Steps To Reproduce

No response

In what environment did you encounter the issue?

Additional information you deem important

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions