Skip to content

Commit

Permalink
fix WithValidator doc (lestrrat-go#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
johejo authored Oct 5, 2021
1 parent 2dfca56 commit 4c29e6c
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions jwt/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,19 +378,15 @@ func WithMinDelta(dur time.Duration, c1, c2 string) ValidateOption {

// WithValidator validates the token with the given Validator.
//
// For example, in order to validate a custom claim value is 'my-claim-value', you would write
//
// v := jwt.NewSingleClaimValidator("my-claim", SingleClaimValidatorFunc(func(c interface{}) error ) {
// v, ok := c.(string)
// if !ok {
// return errors.New("invalid my-claim")
// }
// if v != "my-claim-value" {
// return errors.New("invalid my-claim")
// }
// return nil
// })
// err := jwt.Validate(token, jwt.WithValidator(jwt.NewSingleClaimValidator("my-claim", v)))
// For example, in order to validate tokens that are only valid during August, you would write
//
// validator := jwt.ValidatorFunc(func(_ context.Context, t jwt.Token) error {
// if time.Now().Month() != 8 {
// return fmt.Errorf(`tokens are only valid during August!`)
// }
// return nil
// })
// err := jwt.Validate(token, jwt.WithValidator(validator))
//
func WithValidator(v Validator) ValidateOption {
return newValidateOption(identValidator{}, v)
Expand Down

0 comments on commit 4c29e6c

Please sign in to comment.