【问题标题】:Node JS passport google oauth not working on https?节点 JS 护照谷歌 oauth 不能在 https 上工作?
【发布时间】:2018-10-16 23:44:37
【问题描述】:

我对这个错误感到非常沮丧。这是我部署到 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' 并删除所有浏览器缓存。一切都会按预期进行。

【问题讨论】:

  • 我的猜测是谷歌不会响应不安全的请求,只是因为你的 url 中有https 并不意味着你有 SSL 证书,你需要为你的应用程序获取一个。更多信息在这里devcenter.heroku.com/articles/…

标签: node.js express passport.js


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-27
    • 2019-01-29
    • 2014-08-12
    • 2013-08-18
    • 1970-01-01
    • 2017-08-18
    • 1970-01-01
    • 2014-10-20
    相关资源
    最近更新 更多