Skip to content

Instantly share code, notes, and snippets.

@frostbytten
Created June 12, 2011 11:04
Show Gist options
  • Save frostbytten/1021439 to your computer and use it in GitHub Desktop.
Save frostbytten/1021439 to your computer and use it in GitHub Desktop.
Connect-Auth Facebook Example
// Example taken from https://github.com/ciaranj/connect-auth/issues/45
var fbId= "xxxxxxxxxxxxx";
var fbSecret= "xxxxxxxxxxxxxx";
var fbCallbackAddress= "http://localhost:3000/auth/facebook_callback"
var cookieSecret = "node"; // enter a random hash for security
var express= require('express');
var auth = require('connect-auth')
var app = express.createServer();
app.configure(function(){
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.session({secret: cookieSecret}));
app.use(auth([
auth.Facebook({
appId : fbId,
appSecret: fbSecret,
callback: fbCallbackAddress,
scope: 'email',
failedUri: '/noauth'
})
]));
app.use(app.router);
});
app.get('/auth/facebook', function(req, res) {
req.authenticate("facebook", function(error, authenticated) {
if (authenticated) {
res.redirect("/great");
}
});
});
app.get('/noauth', function(req, res) {
console.log('Authentication Failed');
res.send('Authentication Failed');
});
app.get('/great', function( req, res) {
res.send('Supercoolstuff');
});
app.listen(3000);
@guiomie
Copy link

guiomie commented Aug 20, 2011

The exemple kinda lacks explanation. What does req.authenticate([req.param('method')] in the line req.authenticate([req.param('method')], function(error, authenticated) does? How do you configure properly? I read the facebook doc, but I still cant figure out how to get connect-auth working, authentication failed all the time...?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment