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?

Zeeshan Hassan Memon
  • 8,105
  • 4
  • 43
  • 57
de-bugged
  • 935
  • 4
  • 14
  • 34

1 Answers1

5

If you've only just started and are going to use other Oauth authentications like gmail or twitter. I recommend using passport.js.

It is much simpler. http://passportjs.org/

Sangram Singh
  • 7,161
  • 15
  • 50
  • 79
  • 1
    No, i am targeted only towards facebook, since i need to retrieve user details after authentication. I doubt passport has tat option. – de-bugged Aug 08 '13 at 15:30
  • 1
    @de-bugged, Passport.js supports Facebook as an authentication provider: http://passportjs.org/guide/facebook/ – Blackcoat May 01 '14 at 15:10
  • 1
    Hi @Blackcoat, thnx for the link. Passport has options for authentication via GET. Im looking for Auth using POST. – de-bugged May 01 '14 at 21:31
  • @de-bugged Is it possible to get facebook user profile without using passport/0auth or any other 3rd party plugin? If yes then how? – HARDIK THAKOR Jun 13 '17 at 07:19