Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using jwt-go Library - Key is invalid or invalid type

I am trying to pass in a token to the "Parse(token String, keyFunc Keyfunc)" GO routine defined in this GO-library (http://godoc.org/github.com/dgrijalva/jwt-go) for JWT-token parsing/validation.

When I pass the token to this function -

token, err := jwt.Parse(getToken, func(token *jwt.Token) (interface{}, error) {
        return config.Config.Key, nil
    })

I get an error which says "Key is invalid or invalid type".

My config struct looks like this in config.go file -

config struct {
 Key string
}

Any suggestions to solve this problem? The token I am passing is a JWT token.

like image 600
psbits Avatar asked Dec 02 '22 15:12

psbits


1 Answers

config struct {
 Key string
}

Key needs to be a []byte

like image 124
Jesse Avatar answered Dec 09 '22 20:12

Jesse