Reimplementation of the kratos jwt middleware suited as stream interceptor
(keyFunc jwt.Keyfunc, signingMethod jwt.SigningMethod)
| 172 | |
| 173 | // Reimplementation of the kratos jwt middleware suited as stream interceptor |
| 174 | func jwtAuthFunc(keyFunc jwt.Keyfunc, signingMethod jwt.SigningMethod) grpc_auth.AuthFunc { |
| 175 | return func(ctx context.Context) (context.Context, error) { |
| 176 | token, err := grpc_auth.AuthFromMD(ctx, "bearer") |
| 177 | if err != nil { |
| 178 | return nil, err |
| 179 | } |
| 180 | |
| 181 | claims, err := verifyAndMarshalJWT(token, keyFunc, signingMethod) |
| 182 | if err != nil { |
| 183 | return nil, err |
| 184 | } |
| 185 | |
| 186 | return jwtMiddleware.NewContext(ctx, claims), nil |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | // verifyAndMarshalJWT verifies the token and returns the claims |
| 191 | func verifyAndMarshalJWT(token string, keyFunc jwt.Keyfunc, signingMethod jwt.SigningMethod) (*casJWT.Claims, error) { |