0
私のアプリケーションでパスポート - フェイスブック認証を実装しています。私は次のコードを実装しました。passport-facebookが 'undefined'プロファイルオブジェクトを返します
routes.js
// route for facebook authentication and login
router.get('/facebook', passport.authenticate('facebook', { scope : ['email'] }));
// handle the callback after facebook has authenticated the user
router.get('/facebook/callback', passport.authenticate('facebook', { successRedirect : '/dashboard', failureRedirect : '/'}));
がpassport.js
passport.use(new FacebookStrategy({
clientID : config.facebookAuth.clientID,
clientSecret : config.facebookAuth.clientSecret,
callbackURL : config.facebookAuth.callbackURL,
passReqToCallback : true,
profileFields: ['id', 'emails', 'name']
},
function(token, refreshToken, profile, done){
process.nextTick(function(){
console.log(profile);
User.findOne({ 'username' : profile.name.givenName }, function(err, user){
if (err)
return done(err); // user not found
if (user) {
return done(null, user); // user found, return that user
}else{
var newUser = new User();
newUser.username = profile.name.givenName;
newUser.email = profile.emails[0].value;
newUser.token = token;
newUser.password = "";
// save user to the database
newUser.save(function(err) {
if (err)
throw err;
// if successful, return the new user
return done(null, newUser);
});
}
});
});
}));
ログインボタンFacebookの戦略のコールバック関数で
<a name="facebookLogin" class="btn btn-block btn-lg" href="https://vote-center.herokuapp.com/users/facebook" role="button"><span><img src="images/facebook.png"></span></a>
、私は常に未定義としてプロファイルを取得していますし、実行時にエラーがスローされます。どこが間違っていますか?
以下は参照用のログです。
2016-08-14T07:03:27.995224+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="https://stackoverflow.com/users/facebook/callback?code=AQBxQ6EGmLjBMNayuBNuj_-sfI69qpPwAnF-i9BGQntcLzH0pxXnbbyi1RHSjDfvzmCLphZORiL-M-HajfDWJX65QFODlCXY5sHh5BLEw1fUj_PWsWZNZmQkUK-RkIGU2Ip9XgOyuG9oD3BQkNZRYe0UtvUzRtQuORO4R29OQ37aJV6RFqnYl_SWREZLvGUi5_QN_InZ7OkHxFTn8rIft2t8qtyJCP4h8UH2-2kXjJqahD_E48DHKaUnWvH9UTG-FaT8n2Wa9sRC8JVcGV6t12mH8ajB64b4Wk_96fVG8y11_7dw-7u9BLm4eUzyFr1ecN4" host=vote-center.herokuapp.com request_id=f688bbd9-d77f-446d-833a-9919b3629598 fwd="45.114.61.58" dyno=web.1 connect=0ms service=278ms status=503 bytes=0
2016-08-14T07:03:27.985465+00:00 app[web.1]: undefined
2016-08-14T07:03:27.987413+00:00 app[web.1]: /app/configuration/passport.js:25
2016-08-14T07:03:27.987429+00:00 app[web.1]: User.findOne({ 'username' : profile.name.givenName }, function(err, user){
2016-08-14T07:03:27.987441+00:00 app[web.1]: ^
2016-08-14T07:03:27.987453+00:00 app[web.1]:
2016-08-14T07:03:27.987469+00:00 app[web.1]: at _combinedTickCallback (internal/process/next_tick.js:67:7)
2016-08-14T07:03:27.987482+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:98:9)
2016-08-14T07:03:28.008758+00:00 app[web.1]: npm ERR! Linux 3.13.0-91-generic
2016-08-14T07:03:28.009344+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-08-14T07:03:28.011084+00:00 app[web.1]: npm ERR! Failed at the [email protected] start script 'node ./bin/www'.
2016-08-14T07:03:28.:00 app[web.1]: npm ERR! npm bugs MEN
2016-08-14T07:03:28.012908+00:00 app[web.1]: npm ERR! There is likely additional logging output above.
2016-08-14T07:03:28.017783+00:00 app[web.1]: npm ERR! /app/npm-debug.log
2016-08-14T07:03:28.151473+00:00 heroku[web.1]: Process exited with status 1
2016-08-14T07:03:28.157074+00:00 heroku[web.1]: State changed from up to crashed