Skip to content

Commit

Permalink
Update Parse example to use WithValidMethods (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattt authored Jan 18, 2025
1 parent bc8bdca commit c035977
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions hmac_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit c035977

Please sign in to comment.