3

I am creating a web app with express.js and angular,js, where the client authenticates via facebook. For facebook authentication I use facebook-node-sdk to connect with facebook and retrieve details.

The code works well when authentication is made via a url redirect. But the same code returns no result when I send a POST request from client to invoke the same code

Server Code

app.post('/login', Facebook.loginRequired(), function(req, res){
  var result = {};
  req.facebook.api('/me', function(err, user) {
      console.log(user);
      if(user !== undefined){
        result.status = 1;
        result.name = user.name;
        res.contentType('json');
        res.write(JSON.stringify(result));
        res.render('index')
        res.end();
      }
      else{
        result.status = 0;
        result.name = "Error signing into Facebook";
        res.contentType('json');
        res.write(JSON.stringify(result));
        res.render('/')
        res.end();
      }
    });
});

I have no error when the above code is invoked. console.log shows:

POST /login 302.

So is it possible to authenticate facebook via POST request or should it be always a direct URL request? If so any option to authenticate via POST?

4

1 回答 1

5

如果您刚刚开始并且打算使用其他 Oauth 身份验证,例如 gmail 或 twitter。我推荐使用passport.js。

它要简单得多。http://passportjs.org/

于 2013-08-08T15:28:35.803 回答