Update Parse example to use WithValidMethods

This commit is contained in:
Mattt Zmuda 2024-12-13 05:12:07 -08:00
parent bc8bdca5cc
commit 4f621ae0f0
No known key found for this signature in database
1 changed files with 1 additions and 6 deletions

View File

@ -49,14 +49,9 @@ func ExampleParse_hmac() {
// head of the token to identify which key to use, but the parsed token (head and claims) is provided
// to the callback, providing flexibility.
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.SigningMethodHMAC); !ok {
return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
}
// hmacSampleSecret is a []byte containing your secret, e.g. []byte("my_secret_key")
return hmacSampleSecret, nil
})
}, jwt.WithValidMethods([]string{jwt.SigningMethodHS256.Alg()}))
if err != nil {
log.Fatal(err)
}