-
Notifications
You must be signed in to change notification settings - Fork 205
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
Incorrect documentation / breaking change lead to failed build #72
Comments
Hey @truescotian, my apologies for this. If you look at #69 you can see what lead to this breaking change. The decision was made to have this breaking change in order to fix a security vulnerability. The documentation issue is an oversight on our part and I'll make sure that gets fixed up. A contributing factor to this issue is that up until this point this package has not been versioned. |
Actually, it looks like the documentation issue has already been fixed and is awaiting merge: kylekampy/docs@9cdddf6 |
Hi @grounded042, thanks for the quick response! Glad to see that the docs have been updated. However, I just wanted you to be aware of two potential issues: I seem to be running into similar issues. I hope I go in to enough detail for you:
Output: So my At this point, I'm not really sure where things went wrong when parsing |
In the code snippet
it makes sense with what you are seeing. You would need to do
to have it show up as EDIT: actually, this is a little strange based on: https://play.golang.org/p/botHkNRY-PG |
@truescotian Thinking about this some more I think this has to do with how JSON is parsed into the map claims. I don't have time to dig deeper right now, but that's where I would start looking. |
Same here; to make things work again, I had to explicitly convert the jwtmiddleware.New(jwtmiddleware.Options{
ValidationKeyGetter: func(token *jwt.Token) (interface{}, error) {
claims, ok := token.Claims.(jwt.MapClaims)
if !ok {
return token, errors.New("invalid claims type")
}
if audienceList, ok := claims["aud"].([]interface{}); ok{
auds := make([]string, len(audienceList))
for _, aud := range(audienceList) {
audStr, ok := aud.(string)
if !ok {
return token, errors.New("invalid audience type")
}
auds = append(auds, audStr)
}
claims["aud"] = auds
}
// Verify 'aud' claim
checkAud := claims.VerifyAudience(auth0Aud, false)
if !checkAud {
return token, errors.New("invalid audience")
}
// ... etc Not a big problem perse, but sadly it makes the function way more verbose. Is there a shorter way to cast |
Unfortunately not: https://stackoverflow.com/questions/44027826/convert-interface-to-string-in-golang |
Regarding form3tech-oss/jwt-go Also, by implementing Custom Claims you could kill 3 issues at once
go-jwt-middleware/jwtmiddleware.go Line 204 in 1c6db3c
|
Here's my full solution hopefully it helps someone. main.go:
Next, need to modify go-jwt-middleware so vendor it First add an option for claims
Also need to modify the New() method to set default claims
Finally lets use ParseWithClaims() instead of Parse() and pass in our Claims Option
This worked for me, I'd love to get some feedback on it but it allows leeway support, custom claims support, and solves the issue with []interface{} audiences. All of this could be better solved on the go-jwt side but seems to be a lack of maintenance |
Hey @aaronprice00, sorry for the late reply here. Great work on putting all of that together. Looking through this it looks like a great candidate for The work you've here is a major change to the contract people rely on for this package and if we were to include it we would also look at releasing a new major version of the package. In light of that I'd like to look at moving this work to |
@aaronprice00 Thanks for your solution. Unfortunately I get the following error:
go 1.16 |
@urbantrout can you show use the code for the error you are hitting? |
I think problem solved. I tried those versions of modules
And with them was no need to convert |
I was using
Upgrading to
did not solve the problem. I think it has something to do with this line of code: claims, ok := token.Claims.(jwt.MapClaims) which according to #72 (comment) I have to change to claims, ok := token.Claims.(*MyClaims) // Custom-Claims allows leeway support |
I'm experiencing the same issue and have a work-around for it. I've implemented a custom json parser for my
I'm using the following packages:
|
@hspens
|
We just released the v2.0.0-beta 🥳 ! You can start testing it by running In case of issues fetching the v2 you might want to try I'm closing this issue as now this is part of v2, but feel free to reopen if needed. |
getting error |
Hey @ashish-scalent ! It seems you're trying to do /v2/v2 twice in your go get:) It should be just |
previously we are fetching tokens from requests after jwt middle handler validate the token set in the req context
so in this case if we retrieve the ctxToken from req context something like so token is interface having type string actually so when I tried to retrieve (*jwt.Token) to map with claims it will cause an nil pointer error
is anyone have any idea about this? |
Hey @ashish-scalent , you need to do something like this as described in the README.md:
as now the value will be of type |
PANIC: interface conversion: interface {} is string, not *validator.ValidatedClaims getting panic in that way I forgot to mention that previously |
@ashish-scalent Could you please open a separate issue describing in full detail the issue following the template we provide please?:) It would be great to provide a reproducible of your setup code. |
Hey Sorry my bad you were right I actually forgot to pass no issue from my side, thanks for the instant support |
@ashish-scalent Happy to help!:) Glad you fixed it! |
Hi everyone, we also encountered this problem, I'm putting our solution here in case it will useful for someone. This solution doesn't require using the auth0 v2 sdk which was in beta until recently (if you are implementing from scratch I suggest using it), and does not require vendoring the jwt package to your repository and modify it, and does not require github.com/form3tech-oss/jwt-go which is no longer maintained. The problem as we understand it relies in golang-jwt v3.X which only have a
However, this was solved in golang-jwt v4, which features a
So we decided to import both versions (v3.2.1 and v4) of golang-jwt (unfortunately using only v4 breaks the currently required jwt-go version).
After that, everything worked as expected, no unmarshaling errors and we were able to implement functions such as
|
Description
It seems there is incorrect documentation for Auth0 to address the most recent commit 1c6db3c. When providing options to
github.com/auth0/go-jwt-middleware
, specificallyValidationKeyGetter
, we've always usedgithub.com/dgrijalva/jwt-go
*jwt.Token
, which is currently invalid and throwns the shown error:cannot use func literal (type func(*"github.com/dgrijalva/jwt-go".Token) (interface {}, error)) as type "github.com/form3tech-oss/jwt-go".Keyfunc in field value
I thought that I could just look at the documentation again to build auth (https://auth0.com/docs/quickstart/backend/golang/01-authorization) for an updated solution, but it is still using the old
github.com/dgrijalva/jwt-go
package.I'm not sure why this was deployed to master branch without updating documentation on Auth0's website. If I'm incorrect on this and missing some information, my apologies. Please let me know.
Reproduction
I built my package and it failed. I expected it not to fail. This is a consistent issue. If you would like more information please let me know, otherwise I have followed the Auth0 docs and have not updated my package in over a year.
Environment
github.com/auth0/go-jwt-middleware
github.com/dgrijalva/jwt-go
https://github.com/urfave/negroni
The text was updated successfully, but these errors were encountered: