Skip to content

Update JWT library version #1972

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

Closed
wants to merge 1 commit into from
Closed

Update JWT library version #1972

wants to merge 1 commit into from

Conversation

paemuri
Copy link

@paemuri paemuri commented Aug 23, 2021

I know this commit leads to huge changes, so I'll understand any kind of opinion or feedback.

Also, thanks for this awesome project! :)

@aldas
Copy link
Contributor

aldas commented Aug 23, 2021

Probably will not happen before v5.

Meanwhile you can use JWTConfig.ParseTokenFunc callback for whatever library and version you choose. Documentation has example for that: https://echo.labstack.com/middleware/jwt/#custom-configuration

import (
"github.com/golang-jwt/jwt/v4"
)

...
...
...

signingKey := []byte("secret")

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
  },
}

e.Use(middleware.JWTWithConfig(config))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants