使用 firebase_admin 在 python 中使用 firestore 进行身份验证

问题描述

我在 python 中使用 firestore 和 firebase_admin 并想访问 firebase 的身份验证模块。我通过从 firebase_admin 导入 auth 使用 auth.create_user() 在身份验证中创建了数据。

import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore,auth

cred = credentials.Certificate("servicesAccountKey.json")
firebase_admin.initialize_app(cred)

db = firestore.client()

# <<<<<<<<<<<<<<<<<<<<******************** SignUp ********************>>>>>>>>>>>>>>>>>>>>
def signUp(userObject):
     user = userObject.getUser()

     auth.create_user(uid=user['cnic'],email=user['email'],password=user['password'])     "

现在我想对登录进行身份验证,但无法找到模块 auth.sign_in_with_email_and_password。此模块可用于与 pyerbase 连接的实时数据库,但在与 firebase_admin 连接的 Firestore 中不可用。

def signIn(cnic,password):
    auth.sign_in_with_email_and_password(cnic,password)   

我可以将 auth 与 pyrebase 一起使用,但我必须导入我不想要的 pyrebase 和 firebase_admin。 是否有任何模块可用于 firebase_admin 进行身份验证以登录

解决方法

Firebase 的 Admin SDK 以提升的管理权限运行,并且没有任何登录用户的能力。

您可能需要考虑您的用例:如果您将管理凭据(Admin SDK 需要/使用的)发送给您的常规用户,他们就可以完全访问您的 Firebase 和 Google Cloud 项目。您需要将应用的管理功能与最终用户功能分开,并为最终用户应用使用 REST SDK 或客户端 SDK(如 Pyrebase)。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...