-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
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
@@ -66,11 +66,13 @@ func NewSigner(kid string, key []byte, method jwt.SigningMethod, claims jwt.Clai | |||
} | |||
} | |||
|
|||
type claimsFactory func() jwt.Claims |
There was a problem hiding this comment.
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.
auth/jwt/middleware_test.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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{}
}
auth/jwt/middleware_test.go
Outdated
@@ -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) |
There was a problem hiding this comment.
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{}
}
… for Map and Standard claims factories
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 :) |
auth/jwt/middleware.go
Outdated
@@ -66,11 +66,25 @@ func NewSigner(kid string, key []byte, method jwt.SigningMethod, claims jwt.Clai | |||
} | |||
} | |||
|
|||
type ClaimsFactory func() jwt.Claims |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doc comment! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
woops yeah! done now :)
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