Wednesday, 9 October 2019

Passportjs issue with jwt or is it just me?

So I setup a simple microservice setup using passportjs.All ran on localhost.Original Setup:Client:3000Server:4000 (does everything including auth), tested and works when route is protected via passport.authenticate via jwt.New Setup:Client:3000Server:4000Auth Service:12000 (basically stripped the logic out of the "Server" - mostly copy paste work, and extremely minor renaming to account for new auth service).Now, when the jwt gets sent to the "Server", the "Server"'s passport.authenticate code returns a 401 Unauthorized even though it successfully received it. However, when the "Auth Service" receives the same jwt its own protected route, it gives me its information without any 401 problems at all.I kept the JWT very barebones:const secret = "mysuperdupersecretphrase";jwt.sign({ user }, secret, { expiresIn: '1h' }, (err, token) => {return res.send({user, token});});Again, most of it was copy/pasted over, so the secret and all that stuff remained the same. Very barebones so I'm not sure what the issue is. I even checked on jwt.io that the contents and format was 100% exact same. I added issuer and audience later on, and still didn't work. Hmm.I think I'm missing something here...

Submitted October 09, 2019 at 11:00PM by nathangonz17

No comments:

Post a Comment