I am using the jwt-go library in golang, and using the HS512 algorithm for signing the token. I want to make sure the token is valid and the example in the docs is like this:
token, err := jwt.Parse(myToken, func(token *jwt.Token) (interface{}, error) {
return myLookupKey(token.Header["kid"])
})
if err == nil && token.Valid {
fmt.Println("Your token is valid. I like your style.")
} else {
fmt.Println("This token is terrible! I cannot accept this.")
}
I understand that myToken
is the string token and the keyFunc
gets passed the parsed token, but I don't understand what myLookupKey
function is supposed to do?, and token.Header
doesn't have a kid
value when i print it to console and even thought the token has all the data I put in it, token.Valid
is always false. Is this a bug? How do I verify the token is valid?