要求:将用户从 firebase 帐户导出到其他帐户
我如何导出:使用终端和 Firebase CLI,以及以下脚本
firebase auth:export export.json --format=json --project <valid project id>
这给了我一个包含所有用户的 json 文件。
要导入的代码
import firebase_admin
from firebase_admin import auth
from firebase_admin import credentials
import base64
cred = credentials.Certificate("service.json")
firebase_admin.initialize_app(cred)
def import_with_scrypt():
users = [
auth.ImportUserRecord(
uid='KmlKsGPEDiWtGMkwYyA4VlhLAQ43',
email='testme@test.com',
password_hash=b'base64 key',
password_salt=b'base64 key'
),
]
# All the parameters below can be obtained from the Firebase Console's "Users"
# section. Base64 encoded parameters must be decoded into raw bytes.
hash_alg = auth.UserImportHash.scrypt(
key=base64.b64decode('base64 key'),
salt_separator=base64.b64decode("base64 key"),
rounds=8,
memory_cost=14
)
try:
result = auth.import_users(users, hash_alg=hash_alg)
for err in result.errors:
print('Failed to import user:', err.reason)
except auth.AuthError as error:
print('Error importing users:', error)
import_with_scrypt()
问题:这成功地将用户导入到新的 firebase 帐户。当我尝试使用现有用户凭据在新帐户中登录此用户帐户时,
它抛出一个错误
auth/wrong-password 密码无效或用户没有密码。