func ExampleClaims_Validate() { cl := jwt.Claims{ Subject: "subject", Issuer: "issuer", NotBefore: jwt.NewNumericDate(time.Date(2016, 1, 1, 0, 0, 0, 0, time.UTC)), Expiry: jwt.NewNumericDate(time.Date(2016, 1, 1, 0, 15, 0, 0, time.UTC)), Audience: jwt.Audience{"leela", "fry"}, } err := cl.Validate(jwt.Expected{ Issuer: "issuer", Time: time.Date(2016, 1, 1, 0, 10, 0, 0, time.UTC), }) if err != nil { panic(err) } fmt.Printf("valid!") // Output: valid! }
func ExampleClaims_Validate_withParse() { raw := `eyJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJpc3N1ZXIiLCJzdWIiOiJzdWJqZWN0In0.gpHyA1B1H6X4a4Edm9wo7D3X2v3aLSDBDG2_5BzXYe0` tok, err := jwt.ParseSigned(raw) if err != nil { panic(err) } cl := jwt.Claims{} if err := tok.Claims(sharedKey, &cl); err != nil { panic(err) } err = cl.Validate(jwt.Expected{ Issuer: "issuer", Subject: "subject", }) if err != nil { panic(err) } fmt.Printf("valid!") // Output: valid! }