Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth/jwt: MapClaims: passing #568

Merged
merged 3 commits into from
Jul 13, 2017
Merged

auth/jwt: MapClaims: passing #568

merged 3 commits into from
Jul 13, 2017

Conversation

litriv
Copy link
Contributor

@litriv litriv commented Jul 11, 2017

add claimsFactory type
make NewParser take a claimsFactory instead of an instance of jwt.Claims
use claimsFactory to create a jwt.Claims to pass in to jwt.ParseWithClaims
update NewParser calls in tests to take a claimsFactory instead of a jwt.Claims instance

add claimsFactory type
make NewParser take a claimsFactory instead of an instance of jwt.Claims
use claimsFactory to create a jwt.Claims to pass in to jwt.ParseWithClaims
update NewParser calls in tests to take a claimsFactory instead of a jwt.Claims instance
@@ -66,11 +66,13 @@ func NewSigner(kid string, key []byte, method jwt.SigningMethod, claims jwt.Clai
}
}

type claimsFactory func() jwt.Claims
Copy link
Member

@peterbourgon peterbourgon Jul 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be exported, ClaimsFactory.

@@ -74,7 +74,7 @@ func TestJWTParser(t *testing.T) {
return key, nil
}

parser := NewParser(keys, method, jwt.MapClaims{})(e)
parser := NewParser(keys, method, func() jwt.Claims { return jwt.MapClaims{} })(e)
Copy link
Member

@peterbourgon peterbourgon Jul 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This anonymous func should be provided as a top-level function in the package, e.g.

// MapClaimsFactory is a ClaimsFactory that returns 
// an empty jwt.MapClaims.
func MapClaimsFactory() jwt.Claims {
    return jwt.MapClaims{}
}

@@ -134,15 +134,15 @@ func TestJWTParser(t *testing.T) {
}

// Test for malformed token error response
parser = NewParser(keys, method, &jwt.StandardClaims{})(e)
parser = NewParser(keys, method, func() jwt.Claims { return &jwt.StandardClaims{} })(e)
Copy link
Member

@peterbourgon peterbourgon Jul 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, this anonymous func should be provided as a top-level function in the package, e.g.

// StandardClaimsFactory is a ClaimsFactory that returns 
// an empty jwt.StandardClaims.
func StandardClaimsFactory() jwt.Claims {
    return &jwt.StandardClaims{}
}

@litriv
Copy link
Contributor Author

litriv commented Jul 12, 2017

thanks @peterbourgon - good points, all fixed now. sorry for the sloppiness - a bit pressed for time. let me know of other changes and i'll happily make them :)

@@ -66,11 +66,25 @@ func NewSigner(kid string, key []byte, method jwt.SigningMethod, claims jwt.Clai
}
}

type ClaimsFactory func() jwt.Claims
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc comment! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops yeah! done now :)

@peterbourgon peterbourgon merged commit b42a850 into go-kit:issue-562 Jul 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants