最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

PassportJs谷歌的OAuth2回调抛出这个网站不能达到的错误

IT培训 admin 6浏览 0评论

PassportJs谷歌的OAuth2回调抛出这个网站不能达到的错误

我试图建立“在与谷歌”在一个个人项目,当我致电谷歌AUTH路线我得到一个回调“这个网站不能达到的错误”。

我的路线:

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

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

我的谷歌战略

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附加代码

回答如下:

我想到了 。回调试图访问https://localhost所有我需要做的是改变HTTPS在谷歌API控制台中HTTP和它的工作原理就像一个魅力

PassportJs谷歌的OAuth2回调抛出这个网站不能达到的错误

我试图建立“在与谷歌”在一个个人项目,当我致电谷歌AUTH路线我得到一个回调“这个网站不能达到的错误”。

我的路线:

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

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

我的谷歌战略

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附加代码

回答如下:

我想到了 。回调试图访问https://localhost所有我需要做的是改变HTTPS在谷歌API控制台中HTTP和它的工作原理就像一个魅力

发布评论

评论列表 (0)

  1. 暂无评论