Lasse
Lasse

Reputation: 601

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 ?

EDIT

This is how I try to access the route: Postman of the route

Upvotes: 0

Views: 137

Answers (1)

Leandro Rodrigues
Leandro Rodrigues

Reputation: 1134

Try to remove the quotation marks from the header Authorization.

Im my test here, when I put the quotation marks, it doesn't work.

Ex:

Authorization rather than 'Authorization'

Upvotes: 1

Related Questions