Skip to content

Commit e7ad170

Browse files
committed
Update example to include the New() function rather than the NewWithClaims() function
1 parent e9547a1 commit e7ad170

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

hmac_example_test.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"log"
66
"os"
7-
"time"
87

98
"github.com/golang-jwt/jwt/v5"
109
)
@@ -25,18 +24,17 @@ func init() {
2524

2625
// Example creating, signing, and encoding a JWT token using the HMAC signing method
2726
func ExampleNew_hmac() {
28-
// Create a new token object, specifying signing method and the claims
29-
// you would like it to contain.
30-
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
31-
"foo": "bar",
32-
"nbf": time.Date(2015, 10, 10, 12, 0, 0, 0, time.UTC).Unix(),
33-
})
27+
// Create a new token object, specifying signing method
28+
token := jwt.New(jwt.SigningMethodHS256)
29+
30+
// Optionally, add claims to the token object
31+
token.Claims = jwt.MapClaims{"aud": "someone"}
3432

3533
// Sign and get the complete encoded token as a string using the secret
3634
tokenString, err := token.SignedString(hmacSampleSecret)
3735

3836
fmt.Println(tokenString, err)
39-
// Output: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIiLCJuYmYiOjE0NDQ0Nzg0MDB9.u1riaD1rW97opCoAuRCTy4w58Br-Zk-bh7vLiRIsrpU <nil>
37+
// Output: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJzb21lb25lIn0.F0J37fS_ENgyQg9nxIE0fMS-DX3A11SMh4bvZ7MzD4M <nil>
4038
}
4139

4240
// Example parsing and validating a token using the HMAC signing method

0 commit comments

Comments
 (0)