-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Update JWT middleware #2079
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
Comments
I am not sure if there will be switch off from
|
Will there be any conflict if I use v4.2.0 in my application and the middleware use v3.x? |
If you create your own I think minimal implementation is: config := middleware.JWTConfig{
TokenLookup: "query:token",
ParseTokenFunc: func(auth string, c echo.Context) (interface{}, error) {
keyFunc := func(t *jwt.Token) (interface{}, error) {
if t.Method.Alg() != "HS256" {
return nil, fmt.Errorf("unexpected jwt signing method=%v", t.Header["alg"])
}
return signingKey, nil
}
// claims are of type `jwt.MapClaims` when token is created with `jwt.Parse`
token, err := jwt.Parse(auth, keyFunc)
if err != nil {
return nil, err
}
if !token.Valid {
return nil, errors.New("invalid token")
}
return token, nil
},
} |
Got it. Great thanks. |
Hey but what if when we wants to use a custom claims which is embedding jwt.Standardclaims in it. Then, echo middleware's JWTConfig is showing type error of Claims field. |
Also since jwt.Token have Claims as field therefore jwt.KeyFunc signature is also changed and throwing type error. I think you should consider updating jwt version in echo jwt middleware. |
JWT has updated to v4.2.0 as for now. There're some improvement in v4 - Go module support, use
RegisteredClaims
instead ofStandardClaims
, etc.Do you have any plan to update the JWT middleware to use this new version?
The text was updated successfully, but these errors were encountered: