繁体   English   中英

Passportjs的Google OAuth2回调引发无法访问此网站的错误

[英]PassportJs Google OAuth2 callback throws this site cant be reached error

我正在尝试在个人项目中设置“使用Google登录”,当我调用Google Auth路由时,在回调中出现“无法访问此网站错误”。

我的路线:

    app.get(
  "/user/auth/google",
  passport.authenticate("google", {
    scope: [
      "https://www.googleapis.com/auth/userinfo.profile",
      "https://www.googleapis.com/auth/userinfo.email"
    ]
  })
);

app.get(
  "/user/auth/google/callback",
  passport.authenticate("google", {
    successRedirect: "/wsup",
    failureRedirect: "/login"
  }),
  (req, res) => {
    console.log("callback called");
  }
);

我的Google策略

passport.use(
  new googleStrategy(
    {
      clientID: process.env.googleClientID,
      clientSecret: process.env.googleClientSecret,
      callbackURL: "https://localhost:3000/user/auth/google/callback",
      proxy: true
    },
    (accessToken, refreshToken, profile, done) => {
      console.log(profile.emails[0].value);
      User.findOne({ googleId: profile.id }).then(user => {
        if (user) {
          console.log("existing");
          done(null, user);
        } else {
          new User({ googleId: profile.id })
            .save()
            .then(newUser => done(null, newUser));
        }
      });
    }
  )
);

回应文字:

This site can’t be reached. localhost unexpectedly closed the connection.

我想补充一点,我正在本地主机上对此进行测试,我可以在回调URl中看到来自Google的代码

我想到了 。 回调试图访问https:// localhost,我要做的就是在Google Api控制台中将https更改为http,它的工作原理就像一个超级按钮

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM