2017-04-26 68 views
0

我試圖實現谷歌簽入/簽了我的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); 
       }); 
      } 
     }); 
    }); 
})); 

我拖網上找到答案,什麼都找不到。任何人都可以幫忙嗎?

回答

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

感謝這一點,但它似乎並不成爲問題。我收到的錯誤並沒有指出這一點,只要我用'callbackURL'代替其他任何東西,它就告訴我我缺少這個參數 – DaveB1

+0

你使用的是什麼版本的庫? – ifiok

+0

它是3.10.10 ... – DaveB1