使用护照实现谷歌身份验证 - 错误

问题描述:

我试图实现谷歌签入/签了我的web应用程序,但我发现了以下错误:使用护照实现谷歌身份验证 - 错误

GooglePlusAPIError: Project [project#] is not found and cannot be used for API calls. 

这是我的身份验证设置:

'googleAuth' : { 
     'clientID'  : '***********', 
     'clientSecret' : '***********', 
     'callbackURL' : 'http://localhost:8080/auth/google/callback' 
} 

我在google开发者控制台上创建了应用程序,并将重定向URI设置为与上述auth设置中提到的相同。为了良好的衡量,这里是我的谷歌注册策略:

passport.use(new GoogleStrategy({ 

    clientID  : configAuth.googleAuth.clientID, 
    clientSecret : configAuth.googleAuth.clientSecret, 
    callbackURL  : configAuth.googleAuth.callbackURL, 
}, 
function(token, refreshToken, profile, done) { 
    process.nextTick(function() { 

     User.findOne({ 'google.id' : profile.id }, function(err, user) { 
      if(err) 
       return done(err); 

      if(user) { 
       // if a user is found log them in 
       return done(null, user); 
      } else { 
       // if no user, create it 
       var newUser   = new User(); 
       newUser.google.id   = profile.id; 
       newUser.google.token  = token; 
       newUser.google.name  = profile.displayName; 
       newUser.google.email  = profile.emails[0].value; 

       //save user 
       newUser.save(function(err) { 
        if(err) 
         throw err; 
        return done(null, newUser); 
       }); 
      } 
     }); 
    }); 
})); 

我拖网上找到答案,什么都找不到。任何人都可以帮忙吗?

确认库的版本,您正在使用:

https://github.com/jaredhanson/passport-google

这个库的最新版本不接受这些选项。

看到下面的文档片段:

* Options: 
* - `returnURL` URL to which Google will redirect the user after authentication 
* - `realm`  the part of URL-space for which an OpenID authentication request is valid 
* - `profile` enable profile exchange, defaults to _true_ 
* 
* Examples: 
* 
*  passport.use(new GoogleStrategy({ 
*   returnURL: 'http://localhost:3000/auth/google/return', 
*   realm: 'http://localhost:3000/' 
*  }, 
*  function(identifier, profile, done) { 
*   User.findByOpenID(identifier, function (err, user) { 
*   done(err, user); 
*   }); 
*  } 
* )); 
+0

感谢这一点,但它似乎并不成为问题。我收到的错误并没有指出这一点,只要我用'callbackURL'代替其他任何东西,它就告诉我我缺少这个参数 – DaveB1

+0

你使用的是什么版本的库? – ifiok

+0

它是3.10.10 ... – DaveB1