谷歌Oauth给代码赎回错误

您好我工作的用户通过谷歌帐户login项目(本地主机)我已经实现了谷歌注册。 只要我从我的帐户login,我收到以下错误。

TokenError: Code was already redeemed. at Strategy.OAuth2Strategy.parseErrorResponse (c:\Projects\Internship_rideshare\node_modules\passport-google-oauth\node_modules\passport-oauth\node_modules\passport-oauth2\lib\strategy.js:298:12) at Strategy.OAuth2Strategy._createOAuthError (c:\Projects\Internship_rideshare\node_modules\passport-google-oauth\node_modules\passport-oauth\node_modules\passport-oauth2\lib\strategy.js:345:16) at c:\Projects\Internship_rideshare\node_modules\passport-google-oauth\node_modules\passport-oauth\node_modules\passport-oauth2\lib\strategy.js:171:43 at c:\Projects\Internship_rideshare\node_modules\passport-google-oauth\node_modules\passport-oauth\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:176:18 at passBackControl (c:\Projects\Internship_rideshare\node_modules\passport-google-oauth\node_modules\passport-oauth\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:123:9) at IncomingMessage.<anonymous> (c:\Projects\Internship_rideshare\node_modules\passport-google-oauth\node_modules\passport-oauth\node_modules\passport-oauth2\node_modules\oauth\lib\oauth2.js:142:7) at IncomingMessage.emit (events.js:129:20) at _stream_readable.js:908:16 at process._tickCallback (node.js:355:11) 

我的代码如下(谷歌login代码片段): –

 passport.use(new GoogleStrategy(google, function(req, accessToken, refreshToken, profile, done) { if (req.user) { User.findOne({ google: profile.id }, function(err, existingUser) { if (existingUser) { console.log('There is already a Google+ account that belongs to you. Sign in with that account or delete it, then link it with your current account.' ); done(err); } else { User.findById(req.user.id, function(err, user) { user.google = profile.id; user.tokens.push({ kind: 'google', accessToken: accessToken }); user.profile.displayName = user.profile.displayName || profile.displayName; user.profile.gender = user.profile.gender || profile._json.gender; //user.profile.picture = user.profile.picture || 'https://graph.facebook.com/' + profile.id + '/picture?type=large'; user.save(function(err) { console.log('Google account has been linked.'); done(err, user); }); }); } }); } else { User.findOne({ google: profile.id }, function(err, existingUser) { if (existingUser) return done(null, existingUser); User.findOne({ email: profile._json.email }, function(err, existingEmailUser) { if (existingEmailUser) { console.log('There is already an account using this email address. Sign in to that account and link it with Google manually from Account Settings.' ); done(err); } else { var user = new User(); user.email = profile._json.email; user.google = profile.id; user.tokens.push({ kind: 'google', accessToken: accessToken }); user.profile.displayName = profile.displayName; user.profile.gender = profile._json.gender; //user.profile.picture = 'https://graph.facebook.com/' + profile.id + '/picture?type=large'; user.profile.location = (profile._json.location) ? profile._json.location.name : ''; user.save(function(err) { done(err, user); }); } }); }); } })); 

我困在它上面,请帮我出来..谢谢

问题不在于你的“片段”,看看这些路线。 它应该是谷歌redirect的绝对path。

 router.get('/auth/google/callback', passport.authenticate('google', { failureRedirect: '#/signIn' }), function(req, res) { // absolute path res.redirect('http://localhost:8888/#/home'); }); 

这是已知的问题,请按照此链接到其他解决方法https://github.com/jaredhanson/passport-google-oauth/issues/82

我有同样的问题。

从谷歌控制台重置客户端密钥解决了这个问题。