Skip to content

Commit 29000da

Browse files
committed
Renamed RFC7519Claims to RegisteredClaims
1 parent 02021af commit 29000da

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

claims.go

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ type Claims interface {
1212
Valid() error
1313
}
1414

15-
// RFC7519Claims are a structured version of the JWT Claims Set, as referenced at
16-
// https://datatracker.ietf.org/doc/html/rfc7519#section-4
15+
// RegisteredClaims are a structured version of the JWT Claims Set,
16+
// restricted to Registered Claim Names, as referenced at
17+
// https://datatracker.ietf.org/doc/html/rfc7519#section-4.1
1718
//
18-
// See examples for how to use this with your own claim types
19-
type RFC7519Claims struct {
19+
// This type can be used on its own, but then additional private and
20+
// public claims embedded in the JWT will not be parsed. The typical usecase
21+
// therefore is to embedded this in a user-defined claim type.
22+
//
23+
// See examples for how to use this with your own claim types.
24+
type RegisteredClaims struct {
2025
// the `iss` (Issuer) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.1
2126
Issuer string `json:"iss,omitempty"`
2227

@@ -43,7 +48,7 @@ type RFC7519Claims struct {
4348
// There is no accounting for clock skew.
4449
// As well, if any of the above claims are not in the token, it will still
4550
// be considered a valid claim.
46-
func (c RFC7519Claims) Valid() error {
51+
func (c RegisteredClaims) Valid() error {
4752
vErr := new(ValidationError)
4853
now := TimeFunc()
4954

@@ -74,13 +79,13 @@ func (c RFC7519Claims) Valid() error {
7479

7580
// VerifyAudience compares the aud claim against cmp.
7681
// If required is false, this method will return true if the value matches or is unset
77-
func (c *RFC7519Claims) VerifyAudience(cmp string, req bool) bool {
82+
func (c *RegisteredClaims) VerifyAudience(cmp string, req bool) bool {
7883
return verifyAud(c.Audience, cmp, req)
7984
}
8085

8186
// VerifyExpiresAt compares the exp claim against cmp.
8287
// If required is false, this method will return true if the value matches or is unset
83-
func (c *RFC7519Claims) VerifyExpiresAt(cmp time.Time, req bool) bool {
88+
func (c *RegisteredClaims) VerifyExpiresAt(cmp time.Time, req bool) bool {
8489
if c.ExpiresAt == nil {
8590
verifyExp(nil, cmp, req)
8691
}
@@ -90,7 +95,7 @@ func (c *RFC7519Claims) VerifyExpiresAt(cmp time.Time, req bool) bool {
9095

9196
// VerifyIssuedAt compares the iat claim against cmp.
9297
// If required is false, this method will return true if the value matches or is unset
93-
func (c *RFC7519Claims) VerifyIssuedAt(cmp time.Time, req bool) bool {
98+
func (c *RegisteredClaims) VerifyIssuedAt(cmp time.Time, req bool) bool {
9499
if c.IssuedAt == nil {
95100
return verifyIat(nil, cmp, req)
96101
}
@@ -100,7 +105,7 @@ func (c *RFC7519Claims) VerifyIssuedAt(cmp time.Time, req bool) bool {
100105

101106
// VerifyNotBefore compares the nbf claim against cmp.
102107
// If required is false, this method will return true if the value matches or is unset
103-
func (c *RFC7519Claims) VerifyNotBefore(cmp time.Time, req bool) bool {
108+
func (c *RegisteredClaims) VerifyNotBefore(cmp time.Time, req bool) bool {
104109
if c.NotBefore == nil {
105110
return verifyNbf(nil, cmp, req)
106111
}
@@ -116,7 +121,7 @@ func (c *RFC7519Claims) VerifyNotBefore(cmp time.Time, req bool) bool {
116121
//
117122
// See examples for how to use this with your own claim types
118123
//
119-
// Deprecated: Use RFC7519Claims instead.
124+
// Deprecated: Use RegisteredClaims instead for a forward-compatible way to access claims in a struct.
120125
type StandardClaims struct {
121126
Audience string `json:"aud,omitempty"`
122127
ExpiresAt int64 `json:"exp,omitempty"`

parser_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ var jwtTestData = []struct {
185185
"RFC7519 Claims",
186186
"",
187187
defaultKeyFunc,
188-
&jwt.RFC7519Claims{
188+
&jwt.RegisteredClaims{
189189
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Second * 10)),
190190
},
191191
true,
@@ -217,8 +217,8 @@ func TestParser_Parse(t *testing.T) {
217217
token, err = parser.ParseWithClaims(data.tokenString, jwt.MapClaims{}, data.keyfunc)
218218
case *jwt.StandardClaims:
219219
token, err = parser.ParseWithClaims(data.tokenString, &jwt.StandardClaims{}, data.keyfunc)
220-
case *jwt.RFC7519Claims:
221-
token, err = parser.ParseWithClaims(data.tokenString, &jwt.RFC7519Claims{}, data.keyfunc)
220+
case *jwt.RegisteredClaims:
221+
token, err = parser.ParseWithClaims(data.tokenString, &jwt.RegisteredClaims{}, data.keyfunc)
222222
}
223223

224224
// Verify result matches expectation
@@ -283,8 +283,8 @@ func TestParser_ParseUnverified(t *testing.T) {
283283
token, _, err = parser.ParseUnverified(data.tokenString, jwt.MapClaims{})
284284
case *jwt.StandardClaims:
285285
token, _, err = parser.ParseUnverified(data.tokenString, &jwt.StandardClaims{})
286-
case *jwt.RFC7519Claims:
287-
token, _, err = parser.ParseUnverified(data.tokenString, &jwt.RFC7519Claims{})
286+
case *jwt.RegisteredClaims:
287+
token, _, err = parser.ParseUnverified(data.tokenString, &jwt.RegisteredClaims{})
288288
}
289289

290290
if err != nil {

0 commit comments

Comments
 (0)