问题描述
在通过Passport.js使用Google登录时出现以下错误:
InternalOAuthError: Legacy People API has not been used in project 562040257469 before or it is
disabled. Enable it by visiting
https://console.developers.google.com/apis/api/legacypeople.googleapis.com/overview?
project=562040257469 then retry. If you enabled this API recently,wait a few minutes for the action
to propagate to our systems and retry.
at (/app/node_modules/passport-google-plus-token/lib/index.js:115)
at passBackControl (/app/node_modules/oauth/lib/oauth2.js:132)
at IncomingMessage.<anonymous> (/app/node_modules/oauth/lib/oauth2.js:157)
at IncomingMessage.emit (events.js:203)
at endReadableNT (_stream_readable.js:1145)
at process._tickCallback (next_tick.js:63)
我认为问题出在passport-google-plus-token
。我已启用Google+ API,People API,Drive API和Sheets API。我正在后端进行工作,因此,我将从前端获取访问令牌,该令牌将用于对Passport进行身份验证。
护照认证路线
const passportGoogle = passport.authenticate('googletoken',{
session: false,scope: [
'https://www.googleapis.com/auth/userinfo.profile','https://www.googleapis.com/auth/userinfo.email'
]
})
router.route('/oauth/google/signin')
.post(passportGoogle,UsersController.verification);
护照设置
passport.use('googletoken',new GooglePlusTokenStrategy({
clientID: Keys.Google.Client_Id,clientSecret: Keys.Google.Secret
},async (accesstoken,refreshToken,profile,done) => {
try {
const existingUser =
await User.findOne({ email: profile.emails[0].value });
if (existingUser) {
console.log('User already Exists')
return done(null,existingUser);
}
console.log('User is new')
const newUser = new User({
oauthid: profile.id,email: profile.emails[0].value
});
await newUser.save();
done(null,newUser);
} catch(error) {
done(error,false,error.message);
}
}
));
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)