SSO with Firebase

您是否正在使用 cookie-parser

1 个赞

使用重定向而非 Cookie

大家好,感谢大家的指导,我被 Cookie 方法卡住了,因为我的服务器在不同的域上,而 Safari 浏览器禁止第三方 Cookie。我写了一篇 Stack Overflow 问答,其中包含一种重定向方法,祝大家认证顺利! :stuck_out_tongue_closed_eyes:

我也对将 Firebase 身份验证轻松集成到 Discourse 中非常感兴趣。

嗯,这样做的确切目的是什么?您是否在 discourse 之外的 webapp 中使用了 firebase 身份验证?我正在使用,并且不想更改该设置,我更希望将其设置为“local”(https://firebase.google.com/docs/auth/web/auth-state-persistence)。

给其他人走这条路的一些笔记:

  • 如果使用 Firebase Hosting,请将您的 cookie 命名为“__session”。重写规则会因缓存目的而过滤掉所有其他 cookie。
  • 您需要将上面的相关代码替换为类似以下内容,这样您就不会允许未经验证的电子邮件(重大的安全风险)。
      auth
        .verifyIdToken(idToken)
        .then(function (decodedClaims) {
          // In this case, we are enforcing that the user signed in in the last 5 minutes.
          // and they have a verified email
          if (
            decodedClaims.email_verified &&
            new Date().getTime() / 1000 - decodedClaims.auth_time < 5 * 60
          ) {
            return auth.createSessionCookie(idToken, { expiresIn });
          }
          throw new Error("UNAUTHORIZED REQUEST!");
        })
  • Discourse 中有一个“注销重定向”设置。您可能希望使用它来命中一个清除 __session cookie 的 URL(只能通过后端 API 调用完成),这样用户在再次尝试登录时就不会自动以之前的用户身份登录。
1 个赞

您可以在哪里实现此代码?