Error in JWT example
kolkov opened this issue · 5 comments
kolkov commented
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))
}
kolkov commented
return c.Write(fmt.Sprint("Welcome, %v!", claims.Id)
missing a closing bracket
vvv-v13 commented
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)
qiangxue commented
kolkov commented
@qiangxue No, main problem is:
cannot use jwt.StandardClaims literal (type jwt.StandardClaims) as type jwt.MapClaims in argument to auth.NewJWT
qiangxue commented
ah, you are right. The example code was written for an old version of the implementation. Just fixed it. Thanks.