From 41af31a765bdf7905a6023552fdaa9769b94d51b Mon Sep 17 00:00:00 2001 From: Stefan Arentz Date: Mon, 9 Oct 2023 13:38:32 -0400 Subject: [PATCH 1/2] Add ID to Claims interface --- claims.go | 3 ++- map_claims.go | 5 +++++ registered_claims.go | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/claims.go b/claims.go index d50ff3da..a569c59d 100644 --- a/claims.go +++ b/claims.go @@ -5,7 +5,7 @@ package jwt // common basis for validation, it is required that an implementation is able to // supply at least the claim names provided in // https://datatracker.ietf.org/doc/html/rfc7519#section-4.1 namely `exp`, -// `iat`, `nbf`, `iss`, `sub` and `aud`. +// `iat`, `nbf`, `iss`, `sub`, `aud` and `jti“. type Claims interface { GetExpirationTime() (*NumericDate, error) GetIssuedAt() (*NumericDate, error) @@ -13,4 +13,5 @@ type Claims interface { GetIssuer() (string, error) GetSubject() (string, error) GetAudience() (ClaimStrings, error) + GetID() (string, error) } diff --git a/map_claims.go b/map_claims.go index b2b51a1f..6442fbac 100644 --- a/map_claims.go +++ b/map_claims.go @@ -39,6 +39,11 @@ func (m MapClaims) GetSubject() (string, error) { return m.parseString("sub") } +// GetID implements the Claims interface. +func (m MapClaims) GetID() (string, error) { + return m.parseString("jti") +} + // parseNumericDate tries to parse a key in the map claims type as a number // date. This will succeed, if the underlying type is either a [float64] or a // [json.Number]. Otherwise, nil will be returned. diff --git a/registered_claims.go b/registered_claims.go index 77951a53..465d82e5 100644 --- a/registered_claims.go +++ b/registered_claims.go @@ -61,3 +61,8 @@ func (c RegisteredClaims) GetIssuer() (string, error) { func (c RegisteredClaims) GetSubject() (string, error) { return c.Subject, nil } + +// GetID implements the Claims interface. +func (c RegisteredClaims) GetID() (string, error) { + return c.ID, nil +} From 60dc355c640f941da9aefde60a075cf33249e24a Mon Sep 17 00:00:00 2001 From: Stefan Arentz Date: Mon, 9 Oct 2023 13:43:48 -0400 Subject: [PATCH 2/2] Add ID to Claims interface --- claims.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/claims.go b/claims.go index a569c59d..649c2f08 100644 --- a/claims.go +++ b/claims.go @@ -5,7 +5,7 @@ package jwt // common basis for validation, it is required that an implementation is able to // supply at least the claim names provided in // https://datatracker.ietf.org/doc/html/rfc7519#section-4.1 namely `exp`, -// `iat`, `nbf`, `iss`, `sub`, `aud` and `jti“. +// `iat`, `nbf`, `iss`, `sub`, `aud` and `jti`. type Claims interface { GetExpirationTime() (*NumericDate, error) GetIssuedAt() (*NumericDate, error)