Reputation: 39
Modules:
"express": "~3.0.0",
"jade": ">= 0.0.1",
"mongoose": ">= 3.6.2",
"connect-mongo": "0.3.2",
"nodemailer": ">= 0.3.20",
"socket.io": "0.9",
"cookie": "0.0.5",
"passport": "0.2.3",
"passport-facebook": "*",
"underscore": "*"
-- BACKEND --
Expressjs Configuration:
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', config.root + '/app/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.limit('1mb'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser(''));
app.use(express.session());
app.use(express.static(path.join(config.root, 'public')));
// express/mongo session storage
app.use(express.session({
secret: '',
store: new mongoStore({
url: config.db,
collection : 'sessions'
})
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(app.router);
});
In routers:
app.get('/login/facebook', passport.authenticate('facebook', { display: 'popup', scope: [ 'email', 'user_about_me'], failureRedirect: '/' }));
app.get('/login/facebook/callback', passport.authenticate('facebook', { failureRedirect: '/' }), user.callbackLogin);
In user.callbackLogin :
exports.callbackLogin = function(req, res){
res.render('callback_login');
};
callback_login view has a js script to close the window login popup.
-- FRONTEND --
Utils.popupCenter = function(url, width, height, name) {
var left = (screen.width/2)-(width/2);
var top = (screen.height/2)-(height/2);
return window.open(url, name, "menubar=no,toolbar=no,status=no,width="+width+",height="+height+",toolbar=no,left="+left+",top="+top);
};
Utils.popupCenter('login/facebook', 600, 400, 'Facebook Login');
I'm having troubles with passportjs integration. The popup works, the facebook login is called, and when I click in 'Ok' the facebook returns the data and passport saves in mongodb. But, after this point, nothings works. Expressjs blocking the requests. When I try access another url nodejs stay busy. After spends some time I'm receiving the message "No data received".
Upvotes: 0
Views: 921
Reputation: 1325
I know it's quite late for an answer, but try this project that I put up together:
https://github.com/rafaelfaria/PassportJS-Facebook-Client-Auth
I hope that's what you are looking for.
Upvotes: 1