什么是node.js最好的facebook连接库?

我见过使用node.js和facebook连接的多个工具。 然而,他们中的许多人似乎不完整,过于复杂(非抽象)或不再更新/维护。

我发现了这三个项目:

https://github.com/DracoBlue/node-facebook-client

https://github.com/dominiek/node-facebook

https://github.com/egorFiNE/facebook-connect

https://github.com/ciaranj/node-oauth

这里的作者之一甚至讨论了为什么他再次推出自己的,由于其他实现的缺点:

http://groups.google.com/group/nodejs/browse_thread/thread/bb46cb08e51fdda6

有没有人有真正的经验实际身份validation用户,并使用node.js和Facebook连接存储他们的Facebook的ID在他们的数据库?

我有一个感觉,答案是非常多的,我将不得不build立在上述系统之一上,以使事情变得简单,但我想先检查一下。

编辑:请注意确保使用node.js的STABLE版本

你没有findciaranj的connect-auth

const fbId = ""; #x const fbSecret = ""; #y const fbCallbackAddress= "http://localhost:4000/auth/facebook"; //var RedisStore = require('connect-redis'); var express= require('express'); var auth= require('connect-auth') var app = express.createServer(); app.configure(function(){ app.use(express.cookieDecoder()); app.use(express.logger()); //app.use(connect.session({ store: new RedisStore({ maxAge: 10080000 }) })); app.use(express.session()); app.use(auth( [ auth.Facebook({appId : fbId, appSecret: fbSecret, scope: "email", callback: fbCallbackAddress}) ]) ); }); app.get('/logout', function(req, res, params) { req.logout(); res.writeHead(303, { 'Location': "/" }); res.end(''); }); app.get('/', function(req, res, params) { if( !req.isAuthenticated() ) { res.send('<html> \n\ <head> \n\ <title>connect Auth -- Not Authenticated</title> \n\ <script src="http://static.ak.fbcdn.net/connect/en_US/core.js"></script> \n\ </head><body> \n\ <div id="wrapper"> \n\ <h1>Not authenticated</h1> \n\ <div class="fb_button" id="fb-login" style="float:left; background-position: left -188px"> \n\ <a href="/auth/facebook" class="fb_button_medium"> \n\ <span id="fb_login_text" class="fb_button_text"> \n\ Connect with Facebook \n\ </span> \n\ </a> \n\ </div></body></html>'); } else { res.send( JSON.stringify( req.getAuthDetails()) ); } }); // Method to handle a sign-in with a specified method type, and a url to go back to ... app.get('/auth/facebook', function(req,res) { req.authenticate(['facebook'], function(error, authenticated) { if(authenticated ) { res.send("<html><h1>Hello Facebook user:" + JSON.stringify( req.getAuthDetails() ) + ".</h1></html>") } else { res.send("<html><h1>Facebook authentication failed :( </h1></html>") } }); }); 

app.listen(4000);

Facebook的设置

我发现passport-facebook相当简单而有用。
我也喜欢核心护照模块有80 +authentication策略。
(如微博,谷歌,Foursquare,Github,DIGG,Dropbox)。

从创build者的github自述文件:

 // Set up the strategy passport.use(new FacebookStrategy({ clientID: FACEBOOK_APP_ID, clientSecret: FACEBOOK_APP_SECRET, callbackURL: "http://localhost:3000/auth/facebook/callback" }, function(accessToken, refreshToken, profile, done) { User.findOrCreate({ facebookId: profile.id }, function (err, user) { return done(err, user); }); } )); // Use the authentication app.get('/auth/facebook', passport.authenticate('facebook'), function(req, res){ // The request will be redirected to Facebook for authentication, so // this function will not be called. }); app.get('/auth/facebook/callback', passport.authenticate('facebook', { failureRedirect: '/login' }), function(req, res) { // Successful authentication, redirect home. res.redirect('/'); }); 

我曾经使用过布赖恩野口的一切。 它工作w / node.js v.0.4.x. 你可以在这里find。

它使用mongoose-auth插件本地支持mongodb,这个插件也是由布莱恩编写的。