【问题标题】:what is the authentication flow for a firebase and mean stack architecture?firebase 和平均堆栈架构的身份验证流程是什么?
【发布时间】:2019-11-09 02:30:23
【问题描述】:

我正在做一个以angular为前端,nodejs为后端的项目。

数据库和身份验证机制由 firebase cloud 管理。

问题是我被身份验证机制卡住了。 似乎有很多方法可以使用 Firebase 管理身份验证。

我希望我的后端处理身份验证部分,并且我正在使用电子邮件和密码生态系统进行身份验证。

但似乎有 2 个 npm 包,一个用于 angular firebase,另一个用于 nodejs firebase-admin

由于资源溢出,我在确定使用什么方法以及如何有效地使用它来管理身份验证流程时一团糟。

firebase 中似乎有 signInWithUserNameAndPassword,firebase-admin 中似乎有 signInWithCustomToken

谁能告诉我正确的路径?

我查看了这个answer,但我不知道为什么我们需要将令牌传递回客户端,然后再次将其传递给管理端进行验证?

我的应用程序中的客户端是一个 Web 项目。 我的理解有什么错误吗?

提前谢谢你

【问题讨论】:

    标签: node.js angular firebase firebase-authentication firebase-admin


    【解决方案1】:

    firebase-admin 不支持任何用户身份验证 API。因此,您必须在客户端使用firebase 包和它提供的signInWithEmailAndPassword() API 进行身份验证:https://firebase.google.com/docs/auth/web/password-auth

    【讨论】:

    • 但是我们如何交叉检查它等等。
    • 我在 node js 中使用了客户端 firebase npm 包。
    【解决方案2】:

    您将使用signInWithUserNameAndPassword 方法。一个令牌将返回给您,您可以将其存储在 localStorage 中,这在安全方面是个坏主意,但对于简单的项目练习来说是可以的。或者,您可以使用angular-persistence 或类似的库来保存您的状态。然后,您可以根据他/她的令牌是否存在于状态来验证用户。

    【讨论】:

      猜你喜欢
      • 2015-03-01
      • 1970-01-01
      • 2016-04-22
      • 1970-01-01
      • 1970-01-01
      • 2020-10-31
      • 2019-04-14
      • 2018-01-21
      • 1970-01-01
      相关资源
      最近更新 更多