Package list golang-github-go-kit-kit / 9ed3743
Merge pull request #617 from bcho/fix-doc/auth-jwt auth/jwt: minor doc update Chris Hines authored 3 years ago GitHub committed 3 years ago
2 changed file(s) with 12 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
1212 ```go
1313 import (
1414 stdjwt "github.com/dgrijalva/jwt-go"
15
15
1616 "github.com/go-kit/kit/auth/jwt"
1717 "github.com/go-kit/kit/endpoint"
1818 )
2222 {
2323 kf := func(token *stdjwt.Token) (interface{}, error) { return []byte("SigningString"), nil }
2424 exampleEndpoint = MakeExampleEndpoint(service)
25 exampleEndpoint = jwt.NewParser(kf, stdjwt.SigningMethodHS256)(exampleEndpoint)
25 exampleEndpoint = jwt.NewParser(kf, stdjwt.SigningMethodHS256, jwt.StandardClaimsFactory)(exampleEndpoint)
2626 }
2727 }
2828 ```
3434 ```go
3535 import (
3636 stdjwt "github.com/dgrijalva/jwt-go"
37
37
3838 "github.com/go-kit/kit/auth/jwt"
3939 "github.com/go-kit/kit/endpoint"
4040 )
4444 {
4545 exampleEndpoint = grpctransport.NewClient(...).Endpoint()
4646 exampleEndpoint = jwt.NewSigner(
47 "kid-header",
48 []byte("SigningString"),
49 stdjwt.SigningMethodHS256,
47 "kid-header",
48 []byte("SigningString"),
49 stdjwt.SigningMethodHS256,
5050 jwt.Claims{},
5151 )(exampleEndpoint)
5252 }
6666 import (
6767 stdjwt "github.com/dgrijalva/jwt-go"
6868
69 grpctransport "github.com/go-kit/kit/transport/grpc"
69 grpctransport "github.com/go-kit/kit/transport/grpc"
7070 "github.com/go-kit/kit/auth/jwt"
7171 "github.com/go-kit/kit/endpoint"
7272 )
6969 // Useful in NewParser middleware.
7070 type ClaimsFactory func() jwt.Claims
7171
72 // MapClaimsFactory is a ClaimsFactory that returns
72 // MapClaimsFactory is a ClaimsFactory that returns
7373 // an empty jwt.MapClaims.
7474 func MapClaimsFactory() jwt.Claims {
75 return jwt.MapClaims{}
75 return jwt.MapClaims{}
7676 }
7777
78 // StandardClaimsFactory is a ClaimsFactory that returns
78 // StandardClaimsFactory is a ClaimsFactory that returns
7979 // an empty jwt.StandardClaims.
8080 func StandardClaimsFactory() jwt.Claims {
81 return &jwt.StandardClaims{}
81 return &jwt.StandardClaims{}
8282 }
8383
8484 // NewParser creates a new JWT token parsing middleware, specifying a
8585 // jwt.Keyfunc interface, the signing method and the claims type to be used. NewParser
86 // adds the resulting claims to endpoint context or returns error on invalid token.
86 // adds the resulting claims to endpoint context or returns error on invalid token.
8787 // Particularly useful for servers.
8888 func NewParser(keyFunc jwt.Keyfunc, method jwt.SigningMethod, newClaims ClaimsFactory) endpoint.Middleware {
8989 return func(next endpoint.Endpoint) endpoint.Endpoint {