mikenicholson / passport-jwt

Passport authentication using JSON Web Tokens
MIT License
1.96k stars 213 forks source link

Get token in the verify callback #155

Closed affanshahid closed 5 years ago

affanshahid commented 6 years ago

How do I access the token itself in the verify callback?

I associate tokens with users in the DB, so need it for verification purposes.

zvs001 commented 5 years ago

If I'm right, you shouldn't store jwt token in db. You should save user id or something different within token for verification purposes.

But if you want you can use passReqToCallback option and get your token from request headers req.headers.authorization

mikenicholson commented 5 years ago

I agree with @zvs001. JWT’s are supposed to be stateless, so storing the JWT in the database defeats the point. I don’t think it is worth the extra complexity to support this unusual use case when you can already extract the unparsed token from the request if you really need it.