什么是node.js最好的facebook连接库? [英] What is the best facebook connect library for node.js?
问题描述
我已经看到使用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
有没有人有任何真正的exp实际上认证用户,并使用node.js和facebook连接将他们的Facebook ID存储在他们的数据库中?
我有一种感觉,答案几乎没有,我会必须建立在上述系统之上,使事情变得更简单,但我想先检查。
编辑:注意,请确保使用STABLE版本没有找到ciaranj的 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。使用(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> \\\
\
< head> \\\
\
< title> connect Auth - Not Authenticated< / title> \\\
\
< script src =http://static.ak.fbcdn.net/connect/en_US/core.js>< / script> \\\
\
< / head>< body> \未认证的< / h1> \\\
\
< div class = fb_buttonid =fb-loginstyle =float:left; background-position:left -188px> \\\
\
< a href =/ auth / fb_button_medium> \\\
\\
将跨度ID = fb_login_text 类= fb_button_text > \\\
\
连接Facebook \\\
\
< / span> \\\
\
< / a> \\\
\
< / div>< / body>< / html>');
} else {
res.send(JSON.stringify(req.getAuthDetails()));
}
});
//使用指定的方法类型处理一个登录的方法,并返回一个url ...
app.get('/ auth / facebook',function req,res){
req.authenticate(['facebook'],function(error,authenticated){
if(authenticated){
res.send(< html> h1&您好Facebook用户:+ JSON.stringify(req.getAuthDetails())+。< / h1>< / html>)
}
else {
res。发送(< html>< h1> Facebook验证失败:(< / h1>< / html>)
}
});
});
app.listen(4000);
I've seen multiple tools for working with node.js and facebook connect. However many of them seem incomplete, overly-complex (non abstract) or no longer updated/maintained.
I've found these three projects:
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
Here one of the authors even discusses why he once again rolled his own, due to shortcomings in other implementations:
http://groups.google.com/group/nodejs/browse_thread/thread/bb46cb08e51fdda6
Does anyone have any real experience actually authenticating users and storing their facebook id's in their database using node.js and facebook connect?
I have a feeling that the answer is pretty much no and I'll have to build on top of one of the above systems to make things much simpler, but I wanted to check first.
Edit: Note make sure you use the STABLE version of node.js
Did you not find ciaranj's 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);
这篇关于什么是node.js最好的facebook连接库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!