大佬教程收集整理的这篇文章主要介绍了node.js – NodeJS Passport:通过两种策略进行多重登录 – 序列化问题,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
passport.use(new InstagramStrategy({ clientID: global.INSTAGRAM_CLIENT_ID,clientSecret: global.INSTAGRAM_CLIENT_SECRET,callBACkURL: "http://**.**.**.**:3000/auth/instagram/callBACk" },function(accessToken,refreshToken,profile,donE) { process.nextTick(function () { console.log('Access token: ' + accessToken); global.access_token = accessToken; return done(null,profilE); }); } )); passport.use(new LocalStrategy( function(email,password,donE) { console.log('chec user'); process.nextTick(function() { db.findByEmail(email,function(err,user) { if (!user) { console.log('UnkNown user ' + email); return done(null,false,{ message: 'UnkNown user ' + email }); } if (user.password != crypt.getMD5fromString(password)) { console.log('Invalid password'); return done(null,{ message: 'Invalid password' }); } return done(null,user); }) }); }));
但是我的自定义序列化和deserialize函数不适用于Instagram策略:
/* these FUNCTIONS WORK WITH INSTAGRAM STRATEGY passport.serializeUser(function(user,donE) { done(null,user); }); passport.deserializeUser(function(obj,obj); });*/ /*these ARE FOR LOCAL STRATEGY*/ passport.serializeUser(function(user,donE) {done(null,user._id);}); passport.deserializeUser(function(id,donE) {db.findById(id,user) {done(err,user);});});
如何避免这个bug?我的目标 – 提供登录Instagram,并在成功登录检查后 – 如果用户有本地帐户(通过电子邮件或Instagram昵称),从数据库获取数据.虽然用户应该能够通过本地策略在没有Instagram的情况下登录.谢谢.
我有一些示例代码,演示了一种设置多个身份验证系统的方法.你可以在这里找到它:https://github.com/therealplato/passport-multiauth-demo/blob/master/app.js
几点需要注意:这是为Express 2.x编写的,它以不同于3的方式处理服务器,并且具有不同的语法来发送响应.编辑,演示代码更新为快递3.x.
此外,这里的Google方法是Oauth 1.我无法让Oauth 1 Google Auth在localhost上工作,它会出错…没有方法’CharChodeAt’…
有趣的是,我今天花了很多时间来努力让Oauth 2与我的本地用户很好地合作.所以,如果我能找时间,我会尝试更新Express 3和Oauth 2的演示代码,但没有承诺:)
以上是大佬教程为你收集整理的node.js – NodeJS Passport:通过两种策略进行多重登录 – 序列化问题全部内容,希望文章能够帮你解决node.js – NodeJS Passport:通过两种策略进行多重登录 – 序列化问题所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。