使用护照实施google auth - 错误

时间:2017-04-26 17:49:37

标签: node.js api passport.js

我正在尝试为我的网络应用实施Google登录/注册,但我收到以下错误:

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设置为与上述身份验证设置中提到的相同。为了更好的衡量,这是我的谷歌注册策略:

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

我已经在互联网上寻找答案而一无所获。有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

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

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