Skip to content

Commit 8db555b

Browse files
committed
Change func name to ExampleNewWithClaims
1 parent e7ad170 commit 8db555b

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

hmac_example_test.go

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

89
"github.com/golang-jwt/jwt/v5"
910
)
@@ -23,18 +24,18 @@ func init() {
2324
}
2425

2526
// Example creating, signing, and encoding a JWT token using the HMAC signing method
26-
func ExampleNew_hmac() {
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"}
32-
27+
func ExampleNewWithClaims_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+
})
3334
// Sign and get the complete encoded token as a string using the secret
3435
tokenString, err := token.SignedString(hmacSampleSecret)
3536

3637
fmt.Println(tokenString, err)
37-
// Output: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJzb21lb25lIn0.F0J37fS_ENgyQg9nxIE0fMS-DX3A11SMh4bvZ7MzD4M <nil>
38+
// Output: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIiLCJuYmYiOjE0NDQ0Nzg0MDB9.u1riaD1rW97opCoAuRCTy4w58Br-Zk-bh7vLiRIsrpU <nil>
3839
}
3940

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

0 commit comments

Comments
 (0)