使用 React Native 和 Firebase 自定义令牌在 LDAP 服务器上进行身份验证

Authentication on LDAP Server using React Native and Firebase custom tokens

我正在尝试通过 LDAP 服务器对我的用户(从我的 RN 应用程序)进行身份验证(我已经找到一个尝试进行身份验证的服务器 here,而且它有效!)。每次收到用户的凭据(用户名和密码)时,我都可以使用 Firebase 创建一个自定义令牌,并将其保存在 Firebase 实时数据库中。

主要问题是我不知道如何将我的应用程序连接到 LDAP 服务器,我调查后发现我必须安装类似 openLDAP or ldapjs 的东西,但我不明白必须如何进行身份验证 我的猜测是:

  1. 我的 RN 应用程序中的用户登录
  2. RN 应用程序向 Firebase 发送凭据
  3. Firebase 创建自定义令牌(使用 Firebase 函数生成自定义令牌)
  4. Firebase returns RN 应用程序的自定义令牌
  5. RN应用将token发送给LDAP服务器(服务器有预定的用户和密码用于测试)
  6. LDAP 服务器验证令牌,因此进行身份验证
  7. LDAP 服务器 returns 属性或 "not found" 到 RN 应用程序
  8. RN 应用授予/拒绝对应用的访问权限

任何帮助或建议都会受到欢迎,谢谢 :) 抱歉我的英语不好。

您就快完成了,但不是将 Firebase 自定义令牌发送到 LDAP 服务器,而是在生成 Firebase 令牌之前使用 LDAP 服务器对用户进行身份验证。这两项都必须在受信任的环境中完成,例如您控制的服务器或 Cloud Functions,并且您通常会在该环境中使用 Firebase Admin SDK。

所以:

  1. 用户登录我的 RN 应用程序。
  2. RN 应用程序将凭据发送到可信环境。
  3. 可信环境通过 LDAP 服务器验证凭据。
  4. 可信环境使用 Firebase Admin SDK 创建自定义令牌。如果需要,此令牌可以包含来自 LDAP 服务器的自定义属性,格式为 Custom Claims.
  5. 可信环境returns RN 应用程序的自定义令牌
  6. RN 应用授予/拒绝对应用的访问权限

有关这方面的更多信息,请参阅 Firebase documentation on custom auth。从那里:

To achieve this, you must create a server endpoint that accepts sign-in credentials—such as a username and password—and, if the credentials are valid, returns a custom JWT. The custom JWT returned from your server can then be used by a client device to authenticate with Firebase (iOS, Android, web).