OhAuth是基于Node.js的扩展,用于简化OAuth的开发,实现客户端无重定向的OAuth认证支持。
示例代码:
varExpress=require('express'),app=Express.createServer(Express.favicon(),Express.static(__dirname)),OhAuth=require('./ohauth'),strategies=require('./ohauth-strategies');varcK='consumerKey',cS='consumerSecret',ohAuth=newOhAuth(strategies.twitter(cK,cS,'https://127.0.0.1:1337'),app);app.configure(function(){app.use(app.router);});app.listen(1337);app.get('/',function(req,res){res.sendfile(__dirname+'/index.html');});//whenyou'redone,you'llgetanaccesskeyandanaccesssecretprintingouthereapp.get('/oauth/success',function(req,res){res.send(req.session.credentials);});
评论