jsonwebtoken icon indicating copy to clipboard operation
jsonwebtoken copied to clipboard

Builder for `Validation`?

Open rakshith-ravi opened this issue 2 years ago • 5 comments

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 avatar Sep 08 '23 12:09 rakshith-ravi

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

rakshith-ravi avatar Sep 08 '23 12:09 rakshith-ravi

I don't really want a builder for it no

Keats avatar Sep 08 '23 13:09 Keats

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)

rakshith-ravi avatar Sep 08 '23 15:09 rakshith-ravi

Isn't that a builder?

Keats avatar Sep 11 '23 18:09 Keats

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

rakshith-ravi avatar Sep 12 '23 09:09 rakshith-ravi