简体   繁体   English

无法使用节点和护照通过谷歌获取用户个人资料登录信息

[英]Failed to fetch user profile login via google with node and passport

I am trying to login via google using node and package passport-google-oauth20.我正在尝试使用节点和包passport-google-oauth20通过谷歌登录。 But getting the error - "InternalOAuthError: Failed to fetch user profile".但收到错误 - “InternalOAuthError:无法获取用户配置文件”。 Already enable google plus api.已经启用google plus api。 I am using my business gmail id to access this.我正在使用我的企业 gmail id 来访问它。 Everything is stored in mongodb but not getting the return json as a response.一切都存储在 mongodb 中,但没有得到返回 json 作为响应。 Here is my passport-setup.js code.这是我的passport-setup.js 代码。

const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20');
const keys = require('./keys');
const User = require('../api/models/user');
const mongoose   = require('mongoose');

passport.use(
new GoogleStrategy({
callbackURL: '/users/google/redirect',
clientID: keys.google.clientID,
clientSecret: keys.google.clientSecret
}, (accessToken, refreshToken, profile, done)=>
{

  User.findOne({googleid : profile.id})
  .exec()
  .then(doc=>{
      if(doc)
      {
        //already exist user
        console.log("User exist : "+doc)
      } else{
        const user = new User({
          _id : new mongoose.Types.ObjectId(),
          name : profile.displayName,
          googleid : profile.id
          });
          user.
          save().
          then(result=>{
              console.log("myerror1" +result);
          })
      }
  })
  .catch(err=>{
      console.log("error1" + err);
  });
  console.log(accessToken);
  console.log(profile);
  })
 )

And here is routes code这是路线代码

router.get('/google', passport.authenticate('google', {
scope: ['profile']
}));

router.get('/google/redirect', passport.authenticate('google'), (req, res)=> 
{
res.send(req.user);
});

I am gettting error on google.redirect request.我在 google.redirect 请求中遇到错误。

req.user请求用户

showing me InternalOAuthError向我展示 InternalOAuthError

Have you checked this documentation from google?你有没有从谷歌检查过这个文档 It may help.它可能会有所帮助。

Also, can you add .Strategy at the end of const GoogleStrategy = require('passport-google-oauth20');另外,您可以在const GoogleStrategy = require('passport-google-oauth20');的末尾添加.Strategy const GoogleStrategy = require('passport-google-oauth20'); and see if it helps (or if you get a different error message?看看它是否有帮助(或者你是否收到不同的错误信息?

const GoogleStrategy = require('passport-google-oauth20').Strategy;

I faced the same problem and I solved it doing this:我遇到了同样的问题,我解决了这个问题:

In package.json, change "passport" value to "^0.4.0" and "passport-google-oauth" to "^2.0.0".在 package.json 中,将“passport”值更改为“^0.4.0”,将“passport-google-oauth”更改为“^2.0.0”。 Run "npm install" again.再次运行“npm install”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Node.js “passport-google-oauth2”在 Express 应用程序中传递“无法获取用户配置文件”错误 - Node.js "passport-google-oauth2" delivers "failed to fetch user profile" error in Express application passport-google-oauth 无法获取用户配置文件 ECONNRESET - passport-google-oauth Failed to fetch user profile ECONNRESET 内部 OAuth 错误:无法获取用户配置文件 NodeJs+passport-google-oAuth2 - Internal OAuth Error: Failed to fetch user profile NodeJs+passport-google-oAuth2 使用passport-google-oauth20 InternalOAuthError获取错误:无法获取用户配置文件并且在将标头发送到客户端后无法设置标头 - Getting erros using passport-google-oauth20 InternalOAuthError: Failed to fetch user profile and Cannot set headers after they are sent to the client 使用通行证将用户个人资料与Google个人资料同步 - Synchronize user profile with Google profile using passport Node.js Dwolla Passportjs错误“无法获取用户个人资料” - Node.js Dwolla passportjs error “failed to fetch user profile” Passport-facebook-token返回InternalOAuthError:验证令牌时无法获取用户个人资料 - passport-facebook-token returns InternalOAuthError: Failed to fetch user profile when verifying the token InternalOAuthError:在实施 twitter 策略时无法使用 express 和 passport js 获取用户配置文件 - InternalOAuthError: failed to fetch user profile using express and passport js while implementing twitter strategy 通过oauth令牌passport.js访问用户配置文件 - access user profile via oauth tokens passport.js 如何使用 mongo、passport 和 node js 更新用户的个人资料? - How to update user's profile using mongo, passport and node js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM