Skip to content

Validation Options - Experiment 2: New approach using external Validator struct #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

oxisto
Copy link
Collaborator

@oxisto oxisto commented May 28, 2022

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 a Parser If none is specified, the default NewValidator() is used.

Pros:

  • New API gives us the option to "clean" the validation up from the start and design it the way we want it, potentially moving towards this new API in v5 and sort of making it "optional" in v4.
  • It separates the validation logic from the actual claim, also removing some of the duplicated code from the claims.go file

Cons:

  • We need a new interface (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, only jwt.RegisteredClaims implements this new interface. ParseWithClaims checks for the existence of this interface, if it does not exist, the old way of validating is used
  • There is a slight problem with the Valid() 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 the Parser, this validator is used inside ParseWithClaims and it is also used to set the token.Valid flag, which should be the canonical way to check, if the token is valid. However, if the user calls Valid() 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 deprecate Valid() and make a strong hint, that it should not be used, if used with validation options.

@oxisto oxisto changed the title Validator Options 2: New appraoch using external struct Validator Options: Expriment 2 New approach using external struct May 28, 2022
@oxisto oxisto changed the title Validator Options: Expriment 2 New approach using external struct Validator Options: Expriment 2 New approach using external Validator struct May 28, 2022
@oxisto oxisto changed the title Validator Options: Expriment 2 New approach using external Validator struct Validator Options - Expirement 2 New approach using external Validator struct May 28, 2022
@oxisto oxisto changed the title Validator Options - Expirement 2 New approach using external Validator struct Validator Options - Experiment 2 New approach using external Validator struct May 28, 2022
@oxisto oxisto changed the title Validator Options - Experiment 2 New approach using external Validator struct Validation Options - Experiment 2 New approach using external Validator struct May 28, 2022
@oxisto oxisto changed the title Validation Options - Experiment 2 New approach using external Validator struct Validation Options - Experiment 2: New approach using external Validator struct May 28, 2022
@oxisto
Copy link
Collaborator Author

oxisto commented Aug 27, 2022

Closing this for now as we are preparing for a new v5 api-breaking solution.

@oxisto oxisto closed this Aug 27, 2022
@oxisto oxisto deleted the validation-opts-experiment-2 branch March 27, 2023 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant