go-ozzo/ozzo-routing

Error in JWT example

kolkov opened this issue · 5 comments

Hi! I think this is a error:

 token, err := auth.NewJWT(jwt.StandardClaims{
         Id: id
       }, signingKey)
func NewJWT(claims jwt.MapClaims, signingKey string, signingMethod ...jwt.SigningMethod) (string, error) {
    var sm jwt.SigningMethod = jwt.SigningMethodHS256
    if len(signingMethod) > 0 {
        sm = signingMethod[0]
    }
    return jwt.NewWithClaims(sm, claims).SignedString([]byte(signingKey))
}

return c.Write(fmt.Sprint("Welcome, %v!", claims.Id) missing a closing bracket

Hi.
I use this code, in my project i store id in account_id field.

claims := c.Get("JWT").(*jwt.Token).Claims.(jwt.MapClaims)
accountID := claims["account_id"].(string)

@kolkov Thanks. Is missing the closing bracket the only problem?
@vvv-v13 Thanks for sharing!

@qiangxue No, main problem is:
cannot use jwt.StandardClaims literal (type jwt.StandardClaims) as type jwt.MapClaims in argument to auth.NewJWT

ah, you are right. The example code was written for an old version of the implementation. Just fixed it. Thanks.