|
the documentation only has parsing and validate with Hmac |
Answered by
oxisto
Mar 21, 2023
Replies: 2 comments
|
Try using ParseUnverified, it useful if you want to extract values without validate. Line 430 in 148d710 |
0 replies
|
Please do NOT use We really need to supply an appropriate example using asymmetric keys. Basically it works the same way as for HMAC, but instead of supplying a var myPublicKey *rsa.PublicKey
// Load key from file
myPublicKey = /*...*/
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
// Don't forget to validate the alg is what you expect:
if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
}
return myPublicKey, nil
}) |
0 replies
Answer selected by
oxisto
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please do NOT use
ParseUnverifiedunless you REALLY know what you are doing.We really need to supply an appropriate example using asymmetric keys. Basically it works the same way as for HMAC, but instead of supplying a
[]bytekey, you need to supply a*rsa.PublicKeyin the keyfunc. Something like