1
你好我試圖使用Facebook登錄認證我的應用程序。爲此我使用passport-facebook。我的代碼如下給予:節點js passport-facebook風險驗證碼
//config/passport.js
var passport = require('passport');
var FacebookStrategy = require('passport-facebook').Strategy;
var FACEBOOK_STRATEGY_CONFIG = {
clientID : 'xxxxxxxxxxxxxxxxxxxxx',
clientSecret : 'xxxxxxxxxxxxxxxxxxxxx',
callbackURL :'http://test.com:3000/auth/facebook/callback'
};
function onFacebookStrategyAuth(token, refreshToken, profile, done){
UserCredentials.findOne({'facebook.id' : profile.id}).then(user => {
if(user)
return done(null, user);
else{
var newUser = {};
newUser.facebook.id = profile.id;
newUser.facebook.token = token;
newUser.facebook.name = profile.name.givenName + ' ' + profile.name.familyName;
newUser.facebook.email = profile.emails[0].value;
return UserCredentials.create(newUser);
}
}).then(created => done(null,created)).catch(err => done(err, false));
}
passport.use(new FacebookStrategy(FACEBOOK_STRATEGY_CONFIG, onFacebookStrategyAuth));
我AuthController.js
//controllers/AuthController.js
var passport = require('passport');
module.exports = {
facebook : function(req,res){
passport.authenticate('facebook',{scope : 'email'})(req, res);
},
facebookCallback : function(req, res){
passport.authenticate('facebook',{
successRedirect : '/success',
failureRedirect : '/fail'
})(req, res);
}
};
這裏是我的配置/ route.js
module.exports.routes = {
'/auth/facebook': 'AuthController.facebook',
'/auth/facebook/callback': 'AuthController.facebookCallback',
'/success': {view : 'success'},
'/fail': {view : 'fail' }
}
當我點擊提交按鈕和我的我的提交按鈕行動被定義爲'/ auth/facebook'。但我得到以下錯誤在控制檯上:
/node_modules/passport/lib/middleware/authenticate.js:343
next(err);
^
TypeError: next is not a function
at Strategy.strategy.error (/home/harsh/Desktop/cmbackend/node_modules/passport/lib/middleware/authenticate.js:343:9)
at /home/harsh/Desktop/cmbackend/node_modules/passport-oauth2/lib/strategy.js:166:34
at /home/harsh/Desktop/cmbackend/node_modules/oauth/lib/oauth2.js:177:18
at passBackControl (/home/harsh/Desktop/cmbackend/node_modules/oauth/lib/oauth2.js:123:9)
at IncomingMessage.<anonymous> (/home/harsh/Desktop/cmbackend/node_modules/oauth/lib/oauth2.js:143:7)
at emitNone (events.js:72:20)
at IncomingMessage.emit (events.js:166:7)
at endReadableNT (_stream_readable.js:905:12)
at nextTickCallbackWith2Args (node.js:441:9)
at process._tickDomainCallback (node.js:396:17)