Passport.js验证无法正常工作

Col*_*tes 7 javascript node.js express passport.js

我正试图第一次设置护照,只需要一个谷歌登录选项.我在谷歌apis注册,所以我有所有设置.相关代码在下面,但是当我的应用程序进行'/auth/google/'调用时它只是失败而没有响应或错误消息.我已经开启配置了很多方法都无济于事.我还passport.authenticate('google')用一个带有console.log的匿名函数替换了,以便仔细检查我的web服务是否正常运行.所以我知道它已经到了passport.authenticate('google').

    // serialize session
    passport.serializeUser(function (user, done) {
        done(null, user.id);
    });

    passport.deserializeUser(function (obj, done) {
        done(null, obj);
    }); 

      // use google strategy
  passport.use(new googleStrategy({
      clientID: config.google.clientID,
      clientSecret: config.google.clientSecret,
      callbackURL: config.google.callbackURL,
      scope: 'https://www.google.com/m8/feeds https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'
  },
  function(accessToken, refreshToken, profile, done) {
    console.log(profile);
  }
));


  app.use(passport.initialize());
  app.use(passport.session());


  app.get('/auth/google', passport.authenticate('google'));
  app.get('/auth/google/callback', passport.authenticate('google', { failureRedirect: '/', scope: 'https://www.google.com/m8/feeds' }), signin);
Run Code Online (Sandbox Code Playgroud)

编辑:这是我的http请求,我正在使用角度,这个功能与按钮上的ng-click相关联.

$scope.signIn = function () {
    $http({method: 'GET', url: '/auth/google'}).
        success(function (data, status, headers, config) {
            console.log('success');
        }).
        error(function (data, status, headers, config) {
            console.log(data);
            console.log(status);
            console.log(headers);
            console.log(config);
        });
};
Run Code Online (Sandbox Code Playgroud)

那些日志什么都没有

Mik*_*den 3

您需要done()在中间件内部调用GoogleStrategy

passport.use(new GoogleStrategy({
       ...
  },
  function(accessToken, refreshToken, profile, done) {
    console.log(profile);

    // Add this
    done(null, profile);//profile contains user information
});
Run Code Online (Sandbox Code Playgroud)

在这里找到了这个