node.js - Node JS Passport google oauth 无法在 https 上工作?

标签 node.js express passport.js

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

这是我的passport.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'并删除所有浏览器缓存。一切都会按预期进行。

最佳答案

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

关于node.js - Node JS Passport google oauth 无法在 https 上工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52819947/

相关文章:

node.js - Node - 简单的 xml API 请求

node.js - Angular 5 net::ERR_UNKNOWN_URL_SCHEME 用于来自 express 服务器的图像

node.js - 使用 package-lock 和 npm 链接

javascript - nodeclipse Enide,删除关键字问题

javascript - nodejs - 仅当来自服务器 ip 时才允许请求

node.js - 使用 Passport 和 Nginx 作为代理服务器的身份验证问题 Node.js

jQuery AJAX 调用 Express (nodejs) 框架上的 Passportjs 登录

javascript - 调用不带参数且未定义默认参数的函数

node.js - Node Facebook Passport 仅返回某些字段,无论发送范围如何

node.js - Istanbul 尔 :No coverage information was collected, 退出而不写入覆盖信息