Example creating, signing, and encoding a JWT token using the HMAC signing method
()
| 25 | |
| 26 | // Example creating, signing, and encoding a JWT token using the HMAC signing method |
| 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 | }) |
| 34 | // Sign and get the complete encoded token as a string using the secret |
| 35 | tokenString, err := token.SignedString(hmacSampleSecret) |
| 36 | |
| 37 | fmt.Println(tokenString, err) |
| 38 | // Output: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJmb28iOiJiYXIiLCJuYmYiOjE0NDQ0Nzg0MDB9.u1riaD1rW97opCoAuRCTy4w58Br-Zk-bh7vLiRIsrpU <nil> |
| 39 | } |
| 40 | |
| 41 | // Example parsing and validating a token using the HMAC signing method |
| 42 | func ExampleParse_hmac() { |
nothing calls this directly
no test coverage detected