Skip to content

Commit

Permalink
Renamed RFC7519Claims to StructuredClaims
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed May 29, 2021
1 parent 02021af commit 67be5e3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
16 changes: 8 additions & 8 deletions claims.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ type Claims interface {
Valid() error
}

// RFC7519Claims are a structured version of the JWT Claims Set, as referenced at
// StructuredClaims are a structured version of the JWT Claims Set, as referenced at
// https://datatracker.ietf.org/doc/html/rfc7519#section-4
//
// See examples for how to use this with your own claim types
type RFC7519Claims struct {
type StructuredClaims struct {
// the `iss` (Issuer) claim. See https://datatracker.ietf.org/doc/html/rfc7519#section-4.1.1
Issuer string `json:"iss,omitempty"`

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

Expand Down Expand Up @@ -74,13 +74,13 @@ func (c RFC7519Claims) Valid() error {

// VerifyAudience compares the aud claim against cmp.
// If required is false, this method will return true if the value matches or is unset
func (c *RFC7519Claims) VerifyAudience(cmp string, req bool) bool {
func (c *StructuredClaims) VerifyAudience(cmp string, req bool) bool {
return verifyAud(c.Audience, cmp, req)
}

// VerifyExpiresAt compares the exp claim against cmp.
// If required is false, this method will return true if the value matches or is unset
func (c *RFC7519Claims) VerifyExpiresAt(cmp time.Time, req bool) bool {
func (c *StructuredClaims) VerifyExpiresAt(cmp time.Time, req bool) bool {
if c.ExpiresAt == nil {
verifyExp(nil, cmp, req)
}
Expand All @@ -90,7 +90,7 @@ func (c *RFC7519Claims) VerifyExpiresAt(cmp time.Time, req bool) bool {

// VerifyIssuedAt compares the iat claim against cmp.
// If required is false, this method will return true if the value matches or is unset
func (c *RFC7519Claims) VerifyIssuedAt(cmp time.Time, req bool) bool {
func (c *StructuredClaims) VerifyIssuedAt(cmp time.Time, req bool) bool {
if c.IssuedAt == nil {
return verifyIat(nil, cmp, req)
}
Expand All @@ -100,7 +100,7 @@ func (c *RFC7519Claims) VerifyIssuedAt(cmp time.Time, req bool) bool {

// VerifyNotBefore compares the nbf claim against cmp.
// If required is false, this method will return true if the value matches or is unset
func (c *RFC7519Claims) VerifyNotBefore(cmp time.Time, req bool) bool {
func (c *StructuredClaims) VerifyNotBefore(cmp time.Time, req bool) bool {
if c.NotBefore == nil {
return verifyNbf(nil, cmp, req)
}
Expand All @@ -116,7 +116,7 @@ func (c *RFC7519Claims) VerifyNotBefore(cmp time.Time, req bool) bool {
//
// See examples for how to use this with your own claim types
//
// Deprecated: Use RFC7519Claims instead.
// Deprecated: Use StructuredClaims instead for a forward-compatible way to access claims in a struct.
type StandardClaims struct {
Audience string `json:"aud,omitempty"`
ExpiresAt int64 `json:"exp,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/golang-jwt/jwt"
)

// Example (atypical) using the StandardClaims type by itself to parse a token.
// Example (atypical) using the StructuredClaims type by itself to parse a token.
// The StandardClaims type is designed to be embedded into your custom types
// to provide standard validation features. You can use it alone, but there's
// no way to retrieve other fields after parsing.
Expand Down
10 changes: 5 additions & 5 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ var jwtTestData = []struct {
"RFC7519 Claims",
"",
defaultKeyFunc,
&jwt.RFC7519Claims{
&jwt.StructuredClaims{
ExpiresAt: jwt.NewNumericDate(time.Now().Add(time.Second * 10)),
},
true,
Expand Down Expand Up @@ -217,8 +217,8 @@ func TestParser_Parse(t *testing.T) {
token, err = parser.ParseWithClaims(data.tokenString, jwt.MapClaims{}, data.keyfunc)
case *jwt.StandardClaims:
token, err = parser.ParseWithClaims(data.tokenString, &jwt.StandardClaims{}, data.keyfunc)
case *jwt.RFC7519Claims:
token, err = parser.ParseWithClaims(data.tokenString, &jwt.RFC7519Claims{}, data.keyfunc)
case *jwt.StructuredClaims:
token, err = parser.ParseWithClaims(data.tokenString, &jwt.StructuredClaims{}, data.keyfunc)
}

// Verify result matches expectation
Expand Down Expand Up @@ -283,8 +283,8 @@ func TestParser_ParseUnverified(t *testing.T) {
token, _, err = parser.ParseUnverified(data.tokenString, jwt.MapClaims{})
case *jwt.StandardClaims:
token, _, err = parser.ParseUnverified(data.tokenString, &jwt.StandardClaims{})
case *jwt.RFC7519Claims:
token, _, err = parser.ParseUnverified(data.tokenString, &jwt.RFC7519Claims{})
case *jwt.StructuredClaims:
token, _, err = parser.ParseUnverified(data.tokenString, &jwt.StructuredClaims{})
}

if err != nil {
Expand Down

0 comments on commit 67be5e3

Please sign in to comment.