节点JS通行证Google oauth无法在https上运行?

时间:2018-10-15 15:22:08

标签: node.js express passport.js

我对此错误感到非常沮丧。这是我已部署到heroku https://emm-samrat.herokuapp.com的应用程序。如果单击登录按钮,它将显示空白页。但是,如果将https更改为http,则一切正常。你能告诉我发生了什么事吗?

这是我的password.js代码

    passport.use(
      new GoogleStrategy(
        {
          clientID: keys.googleClientId,
          clientSecret: keys.googleClientSecret,
          //this is for production
          callbackURL: "/auth/google/callback",
          proxy: true
        },
        async (req, accessToken, refreshToken, profile, done) => {
          done(null, profile);
        }
      )
    );

  app.get(
    "/auth/google",
    passport.authenticate("google", {
      prompt: "select_account",
      session: false,
      scope: ["openid", "profile", "email"]
    })
  );

  app.get(
    "/auth/google/callback",
    passport.authenticate("google", { session: false }),
    async (req, res) => {
      const user = await User.findOne({ authId: req.user.id });

      //Stores the User Google Profile ID in session
      req.session.authId = req.user.id;
      if (user) {
        res.redirect("/");
      }
      //If the user is visiting for the first time,
      //he/she should fill the additional form
      res.redirect("/signup");
    }
  );

编辑:如果您的应用程序使用React。确保删除index.js上的import registerServiceWorker from './registerServiceWorker'并删除所有浏览器缓存。一切都会按预期进行。

1 个答案:

答案 0 :(得分:0)

您将需要获取SSL证书,那里有一些免费的证书