javascript - passportjs jwt, client response not getting authenticated -


trying implement login passport-jwt. both signup , login work fine, token produced on login , sent client stores , returns back.

after login authentication request reaches app , nothing happens.. help? :)

jwt strategy

var jwtstrategy = require('passport-jwt').strategy,     extractjwt = require('passport-jwt').extractjwt;     var opts = {}     opts.jwtfromrequest = extractjwt.fromauthheader();     opts.secretorkey = 'secret';     opts.issuer = "http://localhost:3000";     opts.audience = "http://localhost:3000";      passport.use('jwt', new jwtstrategy(opts, function(jwt_payload, done) {          console.log(1)         return user             .findone({where : {username : jwt_payload.email } })             .then(function (user) {                 if(user === null){                     return tempuser                             .findone({where : {username : jwt_payload.email } })                             .then(function(user){                                 return user === null ?                                      done(null, false, 'login error, please try again') :                                     done(null, false, 'email verification needed');                             });                 } else {                     if (bcrypt.comparesync(password, user.datavalues.password)){                                     done(null, user);                      } else {                         done(null, false, 'login error, please try again');                     }              }         });     })); 

route

router.get('/login/check', function(req, res, next) {         passport.authenticate('jwt', function(err, user, info) {             console.log(err)             res.json({'success' : true});         })     }) 

req.query returned client

get /login/check?%22eyjhbgcioijiuzi1niisinr5cci6ikpxvcj9.eyjpzci6mswidxnlcm5hbwuioijzagfplmthcgx1bkbnbwfpbc5jb20ilcjwyxn zd29yzci6iiqyysqxmcq0yxpvslvlmkltukl3ywo0uzlqd1rpvxh0rwiwywphnw92ujrvunv1qufrdnj5z3g5cwttniisimnyzwf0zwrbdci6ijiwmtytmdg tmddumtm6mji6ndyumzuywiisinvwzgf0zwrbdci6ijiwmtytmdgtmddumtm6mji6ntkuotexwiisimlhdci6mtq3mdy1nzy0mcwizxhwijoxndcwnzu3njq wfq.hyhdcmzjne-d6rorxbgc9aqdezzqpgpkwwozicqnc8c%22 - - ms - - 

you telling passport-jwt in authorization header jwt, seems trying pass jwt query string.

try sending header: authentication: "jwt " + token

i wrote tutorial both front , ends of this, might find helpful.

http://blog.slatepeak.com/refactoring-a-basic-authenticated-api-with-node-express-and-mongo/

http://blog.slatepeak.com/build-a-react-redux-app-with-json-web-token-jwt-authentication/


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -