简体   繁体   中英

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.

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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