Question

I'm trying Express 4.0 with passport for a simple Facebook login.

    app.route('/auth/facebook')
    .get(function(req, res, next){
        console.log('Authentication start');

        var aut = passport.authenticate('facebook',
                             {
                                scope: ['read_stream',
                                        'publish_actions']
                             }, function(err) {

            });
     })

This route is supposed to redirect the browser to the Facebook page authentication, but instead nothing happens and the request goes timeout. I'm trying to understand what changed in Express, because in the previous version everything worked.

Was it helpful?

Solution

1) You probably using passport.session, which has a dependency upon express.session being loaded. If so, you have a block that looks like this someplace:

app.configure(function() {
  app.use(express.static('public'));
  app.use(express.cookieParser());
  app.use(express.bodyParser());
  app.use(express.session({ secret: 'keyboard cat' }));
  app.use(passport.initialize());
  app.use(passport.session());
  app.use(app.router);
});

2) express.session is no longer part of the express core app. To get sessions with Express v4, you can use the 'new' express-session to keep things relatively continuous.

In a v4 app, you'll need to require the new express-session module and then use it in place of the original express.session. The modified code would look a little like this:

var express = require('express')
var session = require('express-session')

var app = express()

app.use(session({secret: 'keyboard cat'}))

The express-session page (linked above) includes additional information on how to work with the module.

The bottom line: if you are building an Express v4 app while using examples that were written in Express v3, you'll want to carefully read the docs about the differences between Express versions and how to upgrade. Most examples/docs out there assume Express v3, so you'll need to really understand these:

OTHER TIPS

Maybe you send query with ajax, try follow link:

 <a href="localhost:3000/auth/facebook">FB</a>

I use:

router.get('/facebook', function authenticate(req, res, next) {},
  passport.authenticate('facebook'));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top