passport-facebook returns 'undefined' 个人资料对象

passport-facebook returns 'undefined' profile object

我正在我的应用程序中实施 passport-facebook 身份验证。我已经实现了以下代码。

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);
                });
            }
        });
    });
}));

登录按钮

                <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>

在 facebook 策略的回调函数中,我总是得到未定义的配置文件,因此在 运行 时抛出错误。我哪里错了?

以下日志供参考

2016-08-14T07:03:27.995224+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=GET path="/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 MEN@0.0.0 start script 'node ./bin/www'.
2016-08-14T07:03:28.012358+00: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

我发现了我犯的错误。它与 Facebook 开发者网站上的应用程序注册有关。 Facebook 希望自己在注册时知道域和站点 URL。我以前没有填写过这些信息。一旦我填好,问题就解决了。