Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用passport实现GoogleAuth-错误_Node.js_Api_Passport.js - Fatal编程技术网

Node.js 使用passport实现GoogleAuth-错误

Node.js 使用passport实现GoogleAuth-错误,node.js,api,passport.js,Node.js,Api,Passport.js,我正在尝试为我的web应用程序实现google登录/注册,但出现以下错误: GooglePlusAPIError: Project [project#] is not found and cannot be used for API calls. 这是我的身份验证设置: 'googleAuth' : { 'clientID' : '***********', 'clientSecret' : '***********',

我正在尝试为我的web应用程序实现google登录/注册,但出现以下错误:

GooglePlusAPIError: Project [project#] is not found and cannot be used  for API calls.
这是我的身份验证设置:

    'googleAuth' : {
        'clientID'       : '***********',
        'clientSecret'   : '***********',
        'callbackURL'    : 'http://localhost:8080/auth/google/callback' 
}
我已经在GoogleDeveloper控制台上创建了这个应用程序,并将重定向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);
                });
            }
        });
    });
}));

我在互联网上搜寻答案,却一无所获。有人能帮忙吗?

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

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

请参阅以下文档中的代码段:

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

谢谢你,但这似乎不是问题。我收到的错误根本没有指向这一点,当我用“callbackURL”替换任何其他内容时,它告诉我我缺少此参数您使用的库的哪个版本?您使用的是过时的库。谷歌已经取消了对开放ID的支持。我想你是想用这个,而不是抱歉让我感到痛苦,但我仍然对此感到困惑。我按照新版本的安装说明(即npm insall passport google oauth--save)进行了安装,在我的package.json文件中,我可以看到passport google oauth确实已列出(不仅仅是passport google),所以在我看来,我的设置是正确的?很好。你也许应该通过谷歌切换到googleapis。