@@ -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 .
120125type StandardClaims struct {
121126 Audience string `json:"aud,omitempty"`
122127 ExpiresAt int64 `json:"exp,omitempty"`
0 commit comments