简体   繁体   English

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

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

i'm trying to set up "Sign In with Google" in a personal project and when i call the google auth route i get a "this site cant be reached error" on callback. 我正在尝试在个人项目中设置“使用Google登录”,当我调用Google Auth路由时,在回调中出现“无法访问此网站错误”。

My Routes: 我的路线:

    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");
  }
);

My Google Strategy 我的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));
        }
      });
    }
  )
);

Response Text: 回应文字:

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

i would like to add that i am testing this on localhost and i can see the code from google appended in the callback URl 我想补充一点,我正在本地主机上对此进行测试,我可以在回调URl中看到来自Google的代码

i figured it out . 我想到了 。 the callback was trying to access https://localhost all i had to do was to change https to http in google Api console and it works like a charm 回调试图访问https:// localhost,我要做的就是在Google Api控制台中将https更改为http,它的工作原理就像一个超级按钮

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

相关问题 使用 Google OAuth2 和 Passportjs 重定向到回调 url 时出现 500 内部服务器错误 - Getting a 500 Internal server error when redirecting to the callback url using google OAuth2 with Passportjs password.js Google oauth2策略 - passportjs google oauth2 strategy 错误:invalid_request缺少必需的参数:范围(带有Google OAuth2的Restify和Passportjs) - Error: invalid_request Missing required parameter: scope (Restify & Passportjs w/ Google OAuth2) 如何使用 OAuth2 和 PassportJS 获取 Google Fitness API 数据 - How to get Google Fitness API data using OAuth2 with PassportJS 尝试在Graphql-Yoga Server中将Google Oauth2与Passportjs一起使用 - Trying to use Google Oauth2 with Passportjs in Graphql-Yoga Server OAuth Google 回调抛出错误“连接到本地主机的尝试被拒绝” - OAuth Google callback throws error "connection attempt to localhost was rejected" 带有passportjs + Vue的Google oAuth - Google oAuth with passportjs + Vue invalid_request缺失:在Google Oauth2上使用Google Passportjs进行范围 - invalid_request with missing: scope using Google Passportjs on Google Oauth2 COR 错误:从 React 到 Express 的 Google Oauth(PassportJs 验证) - CORs Error: Google Oauth from React to Express (PassportJs validation) 使用 Firebase 函数的 Google oAuth2 回调问题 - Issue with Google oAuth2 callback using Firebase functions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM