Skip to content
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

Validation Options - Experiment 1: Embedding validation options in claim #208

Closed
wants to merge 2 commits 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 1 is to embedded a validator struct which olds all the necessary information into the claims itself. It is populated by the Parser during Parse. The claim's Valid function can then retrieve the information and adjust the validation.

Pros:

  • Keeps everything as is on the outside, no changes to the exported Valid or VerifyXXX functions, not even with varargs.
  • Pretty simple to use for the user I guess
  • The variable is unexported in the claims itself (v) and should therefore not interfere with json Marshalling

Cons:

  • can only work with jwt.RegisteredClaims (and jwt.StandardClaims) because I have no way to "silently" inject it into MapClaims. I could add a key to the map, but this will be then transparent to the user and might conflict with a custom claim the user has
  • The way the current test is structured in parser_test.go I cannot really test it because it is using the jwt_test package for tests and therefore cannot access the unexpected v field and this leads to some errors in the comparison test.

@oxisto oxisto marked this pull request as draft May 28, 2022 19:12
claims.go Show resolved Hide resolved
claims.go Show resolved Hide resolved
parser.go Show resolved Hide resolved
@oxisto oxisto changed the title Validation Options: Experiment 1 Validation Options - Experiment 1: Embedding validation options in claim 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-1 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