Angular/Node/Express/Passport - Issues when connecting to facebook(CORS) Angular/Node/Express/Passport - Issues when connecting to facebook(CORS) express express

Angular/Node/Express/Passport - Issues when connecting to facebook(CORS)


You can use 'window.location="http://localhost:3000/auth/facebook"'; in your Angular Controller from where you send the request to your Express Server which contains passport.authenticate stuff.

This will stop your angular to call facebook auth dialogue page as AJAX request.

It works for me!


I'm using Angular with Node/Express as well, and the following function works for me with my own backend services (I'm currently not using it with Facebook to be honest), so just check it out:

var allowCrossDomain = function(req, res, next) {    res.header('Access-Control-Allow-Origin', '*');    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');    res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With, Access-Control-Allow-Origin');    res.header("Access-Control-Max-Age", "86400"); // 24 hours    // intercept OPTIONS method    if ('OPTIONS' == req.method) {        res.send(200);    }    else {        next();    }};

Then, you need to use it tin the app.confiure()method as follows:

// configure Expressapp.configure(function() {   app.use(allowCrossDomain);    ...});

It's important to use it BEFORE all other directrives!