Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bearer / passpoet problem on upload files #30

Open
visualight opened this issue Feb 22, 2015 · 0 comments
Open

Bearer / passpoet problem on upload files #30

visualight opened this issue Feb 22, 2015 · 0 comments

Comments

@visualight
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant