DEV Community

Vinh Le
Vinh Le

Posted on

Couldn't enable facebook authentication via passport-facebook in development mode (localhost)

Hi all,
I am developing a web app using Facebook authentication. The technologies I used are passport-facebook and express on server side. Specifically:

route.js

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

   // 
   app.get('/auth/facebook/callback',
      passport.authenticate('facebook', {
         successRedirect: '/',
         failureRedirect: '/login'
      }));
Enter fullscreen mode Exit fullscreen mode

passport.js

const passport = require('passport');
const FacebookStrategy = require('passport-facebook').Strategy;
const keys = require('../config/keys');

passport.use(new FacebookStrategy({
   clientID: keys.facebookClientID,
   clientSecret: keys.facebookClientSecret,
   callbackURL: '/auth/facebook/callback',
   }, (accessToken, refreshToken, profile, done) => {
      console.log(accessToken, profile);
   }
));

Enter fullscreen mode Exit fullscreen mode

I run the app on development server localhost:3000, when go to route: localhost:3000/auth/facebook, an error message pops up:

"Insecure Login Blocked: You can't get an access token or log in to this app from an insecure page. Try re-loading the page as https://"

I tried to Google and StackOverFlow this but couldn't find the answer. Would be very appreciate for your helps!
Thanks all & have a great weekend!

Top comments (2)

Collapse
 
trungducng profile image
Nguyễn Trung Đức • Edited

"Try re-loading the page as https://"". You must serve your route smt like:
https: //localhost:your-port

stackoverflow.com/questions/117449...

Collapse
 
ajayigabriel profile image
Ajayi

Hi, try adding your localhost:*port//auth/facebook/cal... as your callback url and go to facebook. Click on settings and add localhost:*port as your url. See if it will work.