Sunday, 28 May 2017

Express passport middleware not woriking with get request params

I'm building a webserver with node, express, jwt and passport. But when I try to have a route with a get methode:

app.get('/api/:key/lights', passport.authenticate("jwt", {session: false}), function(req, res) {
if (yubiAtHome) {
var sKey = req.params.key;
dbController.checkApiKey(sKey, function(err, bData) {
  if (bData.status) {
    hueController.getLights(function(err, jData) {
      if (err) {
        generateResponse(res, 'get Lights', null, err, 'lLights', 500);
      } else {
        generateResponse(res, 'get Lights', jData, null, 'lLights', 200);
      }
    });
  } else {
     generateResponse(res, 'api key not valid', bData, 'apikey invalid', 'lLights', 500);
     }
    });
   } else {
      generateResponse(res, 'yub not pressent', null, 'yub not pressent', 'lLights', 500);
  }
});

But this route do not work for some reason, if I remove the passport.authenticate("jwt", {session: false}) or remove the params ( the ":key") it works, but otherwise it do not and returns a 401:Unauthorized. How can this be ?



via Lasse

No comments:

Post a Comment