Dagg M.
Dagg M.

Reputation: 68

Passport Facebook strategy in Nodejs doesn't work as of 2023

I have tried to build Passport Oauth login strategy in Nodejs but it seems that it doesn't work as of 2023. Upon clicking login button that triggers standard server API like /auth/facebook/ and setting passport as the middleware, it doesn't even launch FB login popup window, or any window for that purpose.

passport.use(new FacebookStrategy({
  clientID: '**********',
  clientSecret: '************',
  callbackURL: "http://localhost:3000/auth/facebook/cb"
},
  function(accessToken, refreshToken, profile, cb) {
        console.log(profile)
    return cb(null, profile);
  }
));

app.get('/auth/facebook', passport.authenticate('facebook', { display: 'popup' });

app.get('/auth/facebook/cb',  passport.authenticate('facebook'), (req, res, next) => {
  res.send(res.user)
});

I have tried all combinations but nothing happens. Even triggering FB login page manually [as stated on Meta for developers, in that case I got FB login screen (but stanbdard login, without option to confirm data sent) and I managed to receive data into callback API but then the app hangs. Any help would be appreciated, thanks!

Upvotes: 1

Views: 237

Answers (1)

Compty Adel
Compty Adel

Reputation: 51

if you have configured the autorized redirect uri correctly and your app is live be sure to not have cors issue by using the cors module for nodeJs : https://www.npmjs.com/package/cors note : facebook o auth will not work on local host , try to host your back and front end in a free hosting website and try again .

Upvotes: 0

Related Questions