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
-
🚨 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
v5
contains a major rework of core functionalities in thejwt-go
library. This includes support for severalvalidation options as well as a re-design of the
Claims
interface. 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
v4
version is available on the v4 branch at commit 9358574Parsing and Validation Options
Under the hood, a new
validator
struct 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
ParserOption
functions that can be appendedto most
Parse
functions, 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 asexp
ornbf
.iat
claim 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 theWithIssuedAt
parser option.aud
,sub
andiss
, namelyWithAudience
,WithSubject
andWithIssuer
.Changes to the
Claims
interfaceComplete Restructuring
Previously, the claims interface was satisfied with an implementation of a
Valid() error
function. This had several issues:Since all the validation functionality is now extracted into the validator, all
VerifyXXX
andValid
functions have been removed from theClaims
interface. 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
StandardClaims
The two standard claim types supported by this library,
MapClaims
andRegisteredClaims
both implement the necessary functions of this interface. The oldStandardClaims
struct, which has already been deprecated inv4
is 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
Valid
Previously, users could override the
Valid
method 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
ClaimsValidator
interface has been introduced. This interface consists of theValidate() error
function. If the validator sees, that aClaims
struct implements this interface, the errors returned to theValidate
function 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