Example (atypical) using the RegisteredClaims type by itself to parse a token. The RegisteredClaims type is designed to be embedded into your custom types to provide standard validation features. You can use it alone, but there's no way to retrieve other fields after parsing. See the CustomClaimsTy
()
| 15 | // no way to retrieve other fields after parsing. |
| 16 | // See the CustomClaimsType example for intended usage. |
| 17 | func ExampleNewWithClaims_registeredClaims() { |
| 18 | mySigningKey := []byte("AllYourBase") |
| 19 | |
| 20 | // Create the Claims |
| 21 | claims := &jwt.RegisteredClaims{ |
| 22 | ExpiresAt: jwt.NewNumericDate(time.Unix(1516239022, 0)), |
| 23 | Issuer: "test", |
| 24 | } |
| 25 | |
| 26 | token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims) |
| 27 | ss, err := token.SignedString(mySigningKey) |
| 28 | fmt.Println(ss, err) |
| 29 | // Output: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJ0ZXN0IiwiZXhwIjoxNTE2MjM5MDIyfQ.0XN_1Tpp9FszFOonIBpwha0c_SfnNI22DhTnjMshPg8 <nil> |
| 30 | } |
| 31 | |
| 32 | // Example creating a token using a custom claims type. The RegisteredClaims is embedded |
| 33 | // in the custom type to allow for easy encoding, parsing and validation of registered claims. |
nothing calls this directly
no test coverage detected