v5.0.0-rc.1: v5 Pre-Release (#234)
#276
mfridman
announced in
Announcements
Replies: 2 comments 4 replies
-
|
I'll use this discussion here as a place to discuss which PRs we should include in
|
Beta Was this translation helpful? Give feedback.
2 replies
-
|
v5 seems to introduce sensible changes, nice work! One question: When do you intend to fully release v5? I suspect once certain issues have been resolved? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
🚨 New major version
v5(release candidate 1) 🚨Huge kudos to @oxisto for pushing this 10+ year-old project further and building a solid foundation. We don't take breaking changes lightly, but the changes outlined below were necessary to address some of the shortcomings of the previous API.
Version
v5contains a major rework of core functionalities in thejwt-golibrary. This includes support for severalvalidation options as well as a re-design of the
Claimsinterface. Lastly, we reworked how errors work under the hood,which should provide a better overall developer experience.
Starting from
v5, the import path will be:For most users, changing the import path should suffice. However, since we intentionally changed and cleaned some of
the public API, existing programs might need to be adopted. The following paragraphs go through the individual changes
and make suggestions how to change existing programs.
The existing
v4version is available on the v4 branch at commit 9358574Parsing and Validation Options
Under the hood, a new
validatorstruct takes care of validating the claims. A long awaited feature has been the optionto fine-tune the validation of tokens. This is now possible with several
ParserOptionfunctions that can be appendedto most
Parsefunctions, such asParseWithClaims. The most important options and changes are:WithLeeway, which can be used to specific leeway that is taken into account when validating time-based claims, such asexpornbf.iatclaim by default. Usage of this claim is OPTIONAL according to the JWT RFC. The claim itself is also purely informational according to the RFC, so a strict validation failure is not recommended. If you want to check for sensible values in these claims, please use theWithIssuedAtparser option.aud,subandiss, namelyWithAudience,WithSubjectandWithIssuer.Changes to the
ClaimsinterfaceComplete Restructuring
Previously, the claims interface was satisfied with an implementation of a
Valid() errorfunction. This had several issues:Since all the validation functionality is now extracted into the validator, all
VerifyXXXandValidfunctions have been removed from theClaimsinterface. Instead, the interface now represents a list of getters to retrieve values with a specific meaning. This allows us to completely decouple the validation logic with the underlying storage representation of the claim, which could be a struct, a map or even something stored in a database.Supported Claim Types and Removal of
StandardClaimsThe two standard claim types supported by this library,
MapClaimsandRegisteredClaimsboth implement the necessary functions of this interface. The oldStandardClaimsstruct, which has already been deprecated inv4is now removed.Users using custom claims, in most cases, will not experience any changes in the behavior as long as they embedded
RegisteredClaims. If they created a new claim type from scratch, they now need to implemented the proper getterfunctions.
Migrating Application Specific Logic of the old
ValidPreviously, users could override the
Validmethod in a custom claim, for example to extend the validation with application-specific claims. However, this was always very dangerous, since once could easily disable the standard validation and signature checking.In order to avoid that, while still supporting the use-case, a new
ClaimsValidatorinterface has been introduced. This interface consists of theValidate() errorfunction. If the validator sees, that aClaimsstruct implements this interface, the errors returned to theValidatefunction will be appended to the regular standard validation. It is not possible to disable the standard validation anymore (even only by accident).Usage examples can be found in example_test.go, to build claims structs like the following.
This discussion was created from the release v5.0.0-rc.1: `v5` Pre-Release (#234).
Beta Was this translation helpful? Give feedback.
All reactions