Keats / jsonwebtoken

JWT lib in rust
MIT License
1.67k stars 266 forks source link

Builder for `Validation`? #327

Open rakshith-ravi opened 1 year ago

rakshith-ravi commented 1 year ago

Would you be open to a builder pattern for the Validation struct? Right now, I'm using it like so:

jsonwebtoken::decode(
    token,
    &DecodingKey::from_secret(config.jwt_secret),
    {
        let mut validation = Validation::default();

        validation.validate_exp = false;
        validation.validate_nbf = false;

        &validation
    }
);

Would be nice to have a builder pattern for validaton that we can use declaratively

rakshith-ravi commented 1 year ago

I'd be happy to put a PR for this if you're open to it

Keats commented 1 year ago

I don't really want a builder for it no

rakshith-ravi commented 1 year ago

Got it. How about a mutable function to set those variables? Similar to set_audience and set_issuer? That way we can do Validation::default().should_validate_exp(bool)

Keats commented 1 year ago

Isn't that a builder?

rakshith-ravi commented 1 year ago

Yes, but without using a new struct for it. Shouldn't increase the compile times in any way, and also follows the existing convention