I am using the jwt-go library in golang and using the HS512 algorithm to sign a token. I want to make sure that the token is valid, and the example in the docs looks 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 myTokenthis is a string token, but keyFuncreceives the transferred token, but I don’t understand what the function myLookupKeyshould do ?, and it token.Headerdoesn’t kidmatter when I print it to the console and even thought that the token has all the data that I’m in I insert it, token.Validalways a lie. This is mistake? How to confirm that the token is valid?
source
share