Passport.js authenticate not working

I'm trying to set up passport for the first time and going with just a single google sign-in option. I registered with google apis so i have all that setup. the relavant code is below, but when my app makes the '/auth/google/' call it just fails with no response or error message. I've switched up the configuration a bunch of ways to no avail. I've also replaced the passport.authenticate('google') with an anonymous function with a console.log to double check my web service is operating correctly and it is. So I know it is getting to the 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);

EDIT: Here is my http request, I'm using angular and this function is tied to a ng-click on a button.

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

Those logs return nothing


You need to call done() inside the middleware for the GoogleStrategy

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

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

Found this here

链接地址: http://www.djcxy.com/p/14590.html

上一篇: Three.js First Person Controls始终移动摄像头

下一篇: Passport.js验证不起作用