Skip to content

Bearer / passpoet problem on upload files #30

Open
@visualight

Description

@visualight

Hello,

I use passport-http-bearer for my project but i have a problem with upload.
In fact, if I upload a file, it give me a 404 error if I run my App in production mode with Bearer and forever
It looks like bearer again requests the token when there is no need to since it's a session.
If i run my app with : npm start, all work fine.

Here is my code :

Login.js

BearerStrategy = require('passport-http-bearer').Strategy;
var jwt = require('jwt-simple');

function findUser(username, email, fn) {
  for (var i = 0, len = GLOBAL.config.users.length; i < len; i++) {
    var user = GLOBAL.config.users[i];
    if ((user.email === email) && user.username == username) {
      return fn(null, user);
    }
  }
  return fn(null, null);
}

module.exports = function(passport)
{

  passport.use('login', new BearerStrategy({},
    function(token, done)
    {
      process.nextTick(function () {

        var data = jwt.decode(token, 'password');

        findUser(data.username, data.email, function(err, user) {
          if (err) { return done(err); }
          if (!user) { return done(null, false); }
          return done(null, user);
        })
      });
    }
  ));   
}

init.js

var login = require('./login');
var signup = require('./signup');

module.exports = function(passport){

passport.serializeUser(function(user, done) {
  console.log("serializing " + user.username);
  done(null, user);
});

passport.deserializeUser(function(obj, done) {
  console.log("deserializing " + obj);
  done(null, obj);
});

    // Setting up Passport Strategies for Login and SignUp/Registration
    login(passport);
    signup(passport);

}

Route.js

router.post('/upload', isAuthenticated, function(req, res)
    {
        var form = new formidable.IncomingForm();
        form.uploadDir = "temp";

        form.parse(req, function(err, fields, files)
        {

            res.writeHead(200, {'content-type': 'text/plain'});
            res.write('received upload:\n\n');
            res.end(util.inspect({fields: fields, files: files}));
        });
 });

Every file I upload give me a 404 error. I am disconnected from the session.

Can you help me ?

Thank You

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions