auth0 / go-jwt-middleware

A Middleware for Go Programming Language to check for JWTs on HTTP requests
MIT License
1.08k stars 205 forks source link

Sample not working - ValidationKeyGetter - cannot use as jwt.Keyfunc value in struct literal #95

Closed b-venter closed 3 years ago

b-venter commented 3 years ago

Description

image

Reproduction

  1. Download sample from Auth0 tutorial
  2. Extract and cd into folder
  3. go mod init test
  4. go get github.com/codegangsta/negroni
    go get github.com/auth0/go-jwt-middleware
    go get github.com/dgrijalva/jwt-go
    go get github.com/gorilla/mux
    go get github.com/joho/godotenv
    go get github.com/rs/cors
    mv main.go test.go
    go test

    Open with VS Code and the error will appear.

Environment

Please provide the following:

I hope I have not missed something obvious. I tested and the function is acceptable to jwt.Parse (which also takes a jwt.Keyfunc type). Please help! :)

grounded042 commented 3 years ago

Thanks for surfacing this issue @b-venter. We'll get this fixed!

b-venter commented 3 years ago

I did a bit more exploring and this seems linked to the NOTE of this repository: the unmaintained jwt library. To test, I cloned the jwtmiddleware.go file, and changed the jwt library to github.com/golang-jwt/jwt. This appears to have solved the problem I was experiencing, but I am not sure if it will introduce an incompatibility elsewhere? At least for the tutorial, it did not appear to introduce further issues.

If you want to give it a quick test, I put it together for easy running at https://github.com/b-venter/auth0-go-jwt for now.

grounded042 commented 3 years ago

Yes, you are on the right track there. Pulling in github.com/form3tech-oss/jwt-go should fix the issue.

b-venter commented 3 years ago

Actually, I removed github.com/form3tech-oss/jwt-go and put in github.com/golang-jwt/jwt. I guess this error is a further symptom of #73 ?

grounded042 commented 3 years ago

Yeah, it's from that change (see #69 for more details). form3tech was added because there was no other fix at that point. Since then the community has rallied around golang-jwt.

We've got a new version of this package coming out very soon and it uses golang-jwt instead of form3tech. If you're interested in checking it out, https://github.com/auth0/go-jwt-middleware/tree/v2 should point you in the right direction. Using golang-jwt for validation is not in the README, but you can find an example in that branch here: https://github.com/auth0/go-jwt-middleware/blob/v2/validate/jwt-go/examples/main.go

b-venter commented 3 years ago

Thanks @grounded042! The support has been great - which is why I chose to explore Auth0 more in the first place! :) I suspect the above will also address the matter for #96. Should close this issue?

grounded042 commented 3 years ago

@b-venter happy to help! Yes, go ahead and close this since we've solved it for you. I've got a PR open to fix quickstarts code: https://github.com/auth0-samples/auth0-golang-api-samples/pull/35.

And yes, this was the same issue faced in that issue as well.

Thanks for bringing this to our attention!