Comments (11)
Okay, thanks. I'll check it out in a few minutes and get back to you.
from jwtauth.
If you don't correctly type assert the token by removing the ok
check, eg:
52 func FooIndex(w http.ResponseWriter, r *http.Request) {
53 ctx := r.Context()
54 spew.Dump(ctx.Value("jwt"))
55 var ok = true
56 token := ctx.Value("jwt").(*jwt.Token)
57 if !ok {
...
You get an interesting panic:
(*jwt.Token)(0xc420062870)({
Raw: (string) (len=140) "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0NzM4MzM4NjIsImlhdCI6MTQ3Mzc0NzQ2MiwidWlkIjoxM30.2-kOSbYyWNAJ2KEBrfxLqrRKY0C9mNopsq6VFzm05hI",
Method: (*jwt.SigningMethodHMAC)(0xc4200d4820)({
Name: (string) (len=5) "HS256",
Hash: (crypto.Hash) 5
}),
Header: (map[string]interface {}) (len=2) {
(string) (len=3) "alg": (string) (len=5) "HS256",
(string) (len=3) "typ": (string) (len=3) "JWT"
},
Claims: (map[string]interface {}) (len=3) {
(string) (len=3) "exp": (float64) 1.473833862e+09,
(string) (len=3) "iat": (float64) 1.473747462e+09,
(string) (len=3) "uid": (float64) 13
},
Signature: (string) (len=43) "2-kOSbYyWNAJ2KEBrfxLqrRKY0C9mNopsq6VFzm05hI",
Valid: (bool) true
})
2016/09/13 16:31:09 http: panic serving 127.0.0.1:50206: interface conversion: interface {} is *jwt.Token, not *jwt.Token
from jwtauth.
Thanks @bradleyfalzon, that's due to a mismatch between the version of jwt-go
that jwtauth
vendors, and what I was using (latest, unvendored). Vendoring the same version as jwtauth
and removing a no-longer-necessary cast unfortunately lands me back at the same issue.
Here's the output I see after hitting the example server with http http://localhost:8080 --follow --all --session=yargevad
:
context.Background.WithValue(&http.contextKey{name:"http-server"}, &http.Server{Addr:":8080", Handler:(*chi.Mux)(0xc42001a1e0), ReadTimeout:0, WriteTimeout:0, TLSConfig:(*tls.Config)(0xc42008c6e0), MaxHeaderBytes:0, TLSNextProto:map[string]func(*http.Server, *tls.Conn, http.Handler){"h2":(func(*http.Server, *tls.Conn, http.Handler))(0xb40c0), "h2-14":(func(*http.Server, *tls.Conn, http.Handler))(0xb40c0)}, ConnState:(func(net.Conn, http.ConnState))(nil), ErrorLog:(*log.Logger)(nil), disableKeepAlives:0, nextProtoOnce:sync.Once{m:sync.Mutex{state:0, sema:0x0}, done:0x1}, nextProtoErr:error(nil)}).WithValue(&http.contextKey{name:"local-addr"}, &net.TCPAddr{IP:net.IP{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, Port:8080, Zone:""}).WithCancel.WithCancel.WithValue(&chi.contextKey{name:"RouteContext"}, &chi.Context{URLParams:chi.params(nil), RoutePath:"/", RoutePattern:"/", RoutePatterns:[]string{"/foo", "/"}}).WithValue("jwt", &jwt.Token{Raw:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0NzM4MzQzMjQsImlhdCI6MTQ3Mzc0NzkyNCwidWlkIjoxM30.7PYt8BkVYvM76m5qUtYocuZXnD5Lp2TefnBtEuklFl8", Method:(*jwt.SigningMethodHMAC)(0xc4200cea40), Header:map[string]interface {}{"alg":"HS256", "typ":"JWT"}, Claims:map[string]interface {}{"exp":1.473834324e+09, "iat":1.473747924e+09, "uid":13}, Signature:"7PYt8BkVYvM76m5qUtYocuZXnD5Lp2TefnBtEuklFl8", Valid:true}).WithValue("jwt.err", <nil>)
no auth context available!
from jwtauth.
ah yes, that would do it. jwtauth latest stable doesn't support jwt-go v3.0
I will update the README right now to note jwtauth requires https://github.com/dgrijalva/jwt-go/tree/v2.7.0 and that there is a PR here #8 for jwt-go v3.0 support
TBH, jwt-go made some poor design decisions about its code structure, which I think some of its been improved, but this is the reason I wasn't rushing to get to the latest version.
from jwtauth.
@yargevad is your example in the first post working now?
from jwtauth.
Unfortunately not, it's still hitting the no auth context available!
case.
from jwtauth.
@yargevad can you try to run https://github.com/goware/jwtauth/blob/master/_example/main.go ? I just whipped this up and it works great. As well, what happens if you run: go test -v in the project? the tests should pass as well.
from jwtauth.
Looks like this was entirely due to the vendoring errors on my part. The newer package was still being used.
Thanks for the sanity check & sorry for the noise!
from jwtauth.
no problem at all, thanks for helping me fix the docs! best regards.
from jwtauth.
as a note hoping to save others from some headache, I was having the same error:
http: panic serving 127.0.0.1:50206: interface conversion: interface {} is *jwt.Token, not *jwt.Token
Only vendoring dgrijalva/[email protected] didn't solve this, I also had to vendor this package itself, i.e. goware/jwtauth
As I am new to go I am not sure if this is intended or some packaging or vendoring error...
Anyway, thx for this package 👍
from jwtauth.
@DiknT thanks for the note and no prob!
from jwtauth.
Related Issues (20)
- How set expires time in MapClaims HOT 1
- jwtauth: token is expired HOT 2
- Having a hard time setting up a custom authenticator function
- Move away from unmaintained dgrijalva/jwt-go HOT 10
- I seem to be having issues and errors with NBF HOT 4
- go get github.com/go-chi/jwtauth fails HOT 1
- Getting same token for every request HOT 3
- `null` values in token lead to panic in jwtauth.Authenticator HOT 5
- Altering Validation Options to jwt.Validate() HOT 1
- README and Comments Corrections After JWT Lib Change HOT 1
- int turns float64 after decode HOT 1
- OIDC Discovery functionality HOT 2
- How to determine token type on Verify? HOT 2
- Usage with Auth0 with ID Token HOT 1
- TokenFromQuery is missing in Verifier HOT 5
- How to use JWT expiration? HOT 1
- jwt.Validate in jwtauth.Authenticator package error HOT 2
- Getting 401 unauthorized when passing token on multiple services
- Allow users to retrieve JWT from a query and cookie with a specified name HOT 1
- Missing error handling when set claim fields
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jwtauth.