auth/jwt: MapClaims: passing#568
Merged
peterbourgon merged 3 commits intogo-kit:issue-562from Jul 13, 2017
litriv:issue-562
Merged
auth/jwt: MapClaims: passing#568peterbourgon merged 3 commits intogo-kit:issue-562from litriv:issue-562
peterbourgon merged 3 commits intogo-kit:issue-562from
litriv:issue-562
Conversation
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
auth/jwt/middleware.go
Outdated
| } | ||
| } | ||
|
|
||
| type claimsFactory func() jwt.Claims |
Member
There was a problem hiding this comment.
This should be exported, ClaimsFactory.
auth/jwt/middleware_test.go
Outdated
| } | ||
|
|
||
| parser := NewParser(keys, method, jwt.MapClaims{})(e) | ||
| parser := NewParser(keys, method, func() jwt.Claims { return jwt.MapClaims{} })(e) |
Member
There was a problem hiding this comment.
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{}
}
auth/jwt/middleware_test.go
Outdated
|
|
||
| // Test for malformed token error response | ||
| parser = NewParser(keys, method, &jwt.StandardClaims{})(e) | ||
| parser = NewParser(keys, method, func() jwt.Claims { return &jwt.StandardClaims{} })(e) |
Member
There was a problem hiding this comment.
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{}
}… for Map and Standard claims factories
Contributor
Author
|
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 :) |
| } | ||
| } | ||
|
|
||
| type ClaimsFactory func() jwt.Claims |
Contributor
Author
There was a problem hiding this comment.
woops yeah! done now :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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