Created
June 12, 2011 11:04
-
-
Save frostbytten/1021439 to your computer and use it in GitHub Desktop.
Connect-Auth Facebook Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
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
This was a proof-of-concept for a bug fix which has now been released. Please see the example application from https://github.com/ciaranj/connect-auth. Everything should be working according to the example middleware in the app.js