go-chi / jwtauth

JWT authentication middleware for Go HTTP services
MIT License
550 stars 91 forks source link

Interface conversion error when running example: #16

Closed slavabobik closed 7 years ago

slavabobik commented 7 years ago

Hi. I'm trying to run the example:

r.Get("/secret", func(w http.ResponseWriter, r *http.Request) {
            ctx := r.Context()
            token := ctx.Value("jwt").(*jwt.Token)

            render.JSON(w, r, token)
})

and get the error panic: interface conversion: interface {} is *jwt.Token, not *jwt.Token I'm a little bit confused, because if I try to run reflect.typeOf(token) - token has type *jwt.Token. Could you say please, is there a way to solve this?

P.S. Also, I'm tried to vendor dgrijalva/jwt-go 2.7.0 package, but got the same error

pandemicsyn commented 7 years ago

Just ran into this as well. Incase you're still having this issue. The problem is that the library vendor's dgrijalva/jwt-go (which is sort of a no-no for libraries), you'll need to strip it out. For example if you're using glide just throw a -v on glide up or the like.

slavabobik commented 7 years ago

@pandemicsyn Thx! I've solved the issue, my bad.

VojtechVitek commented 7 years ago

@pandemicsyn @SlavaBobik can you please document it to the README.md file to warn other people? PRs welcome!

slavabobik commented 7 years ago

@VojtechVitek I just use vendoring tool wrong. What I should document in your point of view ?

VojtechVitek commented 7 years ago

nvm, it's documented already