Passport.js验证无法正常工作

时间:2013-07-02 12:06:57

标签: javascript node.js express passport.js

我正在尝试首次设置护照并只使用一个谷歌登录选项。我在谷歌apis注册,所以我有所有设置。相关代码在下面,但当我的应用程序进行'/auth/google/'调用时,它只是失败而没有响应或错误消息。我已经开启配置了很多方法都无济于事。我还用一个带有console.log的匿名函数替换了passport.authenticate('google'),以便仔细检查我的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);

编辑: 这是我的http请求,我正在使用angular,这个功能与按钮上的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);
        });
};

那些日志什么都不返回

1 个答案:

答案 0 :(得分:3)

您需要在中间件内为done()

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

    // Add this
    done(null, profile);//profile contains user information
});

找到此here

相关问题