Validation Options - Experiment 2: New approach using external Validator
struct
#209
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is part of a series of experiments, to see which options we have to implement validation options in a backwards compatible way. I want to get a fell about our options first and some feedback from the community, before we implement all desired options. I am looking to gather feedback here: #211
Option 2 is creating a completely new struct, called
Validator
, which takes care of the actual validation. A validator takes certain options (using functional options), such as leeway, etc. and can be passed to aParser
If none is specified, the defaultNewValidator()
is used.Pros:
Cons:
ClaimsV2
for now, can also be unexported probably) that is used to retrieve the needed values for validation (exp, nbf, etc.) to the validator. Currently, onlyjwt.RegisteredClaims
implements this new interface.ParseWithClaims
checks for the existence of this interface, if it does not exist, the old way of validating is usedValid()
function of a claim. As long as the default validator without any options is used, it is fine. However, if a validator with options, e.g. is passed to theParser
, this validator is used insideParseWithClaims
and it is also used to set thetoken.Valid
flag, which should be the canonical way to check, if the token is valid. However, if the user callsValid()
on the claim, this will not take the validator with the options but the default one (because we have no way to supply the validator to the claim in this PR). Therefore, we should probably deprecateValid()
and make a strong hint, that it should not be used, if used with validation options.