Skip to content

Commit c035977

Browse files
authored
Update Parse example to use WithValidMethods (#425)
1 parent bc8bdca commit c035977

File tree

1 file changed

+1
-6
lines changed

1 file changed

+1
-6
lines changed

hmac_example_test.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,9 @@ func ExampleParse_hmac() {
4949
// head of the token to identify which key to use, but the parsed token (head and claims) is provided
5050
// to the callback, providing flexibility.
5151
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
52-
// Don't forget to validate the alg is what you expect:
53-
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
54-
return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
55-
}
56-
5752
// hmacSampleSecret is a []byte containing your secret, e.g. []byte("my_secret_key")
5853
return hmacSampleSecret, nil
59-
})
54+
}, jwt.WithValidMethods([]string{jwt.SigningMethodHS256.Alg()}))
6055
if err != nil {
6156
log.Fatal(err)
6257
}

0 commit comments

Comments
 (0)