How do I import an existing app's users into firebase's Simple Login with email / password.
I have keys and hashes and a user collection with user data. Is it possible to just import it or do I have to use firebase's user api.
// ... You can import user accounts from a file into your Firebase project by using the Firebase CLI's auth:import command. For example: Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License.
While this feature is also available in the Firebase CLI , the Admin SDK lets you upload existing users from an external authentication system or other Firebase project programmatically without having to create intermediate CSV or JSON files. The user import API offers the following advantages:
The Firebase Admin SDK provides the auth.importUsers () API for importing users in bulk to Firebase Authentication with elevated privileges.
Ability to migrate users from another Firebase project. Optimization for speedy and efficient bulk import operations. This operation processes users without checking for uid, email, phoneNumber or other identifier duplication. Ability to migrate existing or create new OAuth users (Google, Facebook, etc).
The current best way to import existing user accounts from another service into Firebase for use within Firebase Simple Login is to call createUser(email, password, callback)
for each of the email address / password combinations, provided you have them. There is currently no out-of-the-box way to import user email addresses and password hashes into Firebase Simple Login, though ping [email protected] and there may be a way to do this.
If you already have an existing authentication mechanism that you'd like to continue using, rather than using Firebase Simple Login, check out custom token generation, which will allow you to continue using your existing authentication. This would require you to generate a JSON Web Token (JWT) when each user authenticates, and this token's payload could then be used in your security rules, as described here: https://www.firebase.com/docs/security/security-rules.html.
Update as of 11/2019
Very first step, make sure to install Firebase Tools, the command for this npm install -g firebase-tools
, I assume that you have installed Node.js
and npm
before.
Hit in your terminal firebase login
to log in to the account from which you want to export (you might be already logged in btw).
Export your emails and password by using firebase auth:export database.json --project projectName
.
Now firebase logout
and firebase login
to the account where you want to import.
Go to Console
-> Project
-> Authentication
-> Password hash parameter
of the project from which you're exporting (this is very important, if you'd take parameters from that one to which you import it won't work).
There you can see something like that:
hash_config {
algorithm: SCRYPT,
base64_signer_key: <long string of random characters>,
base64_salt_separator: <short string of random characters>,
rounds: 8,
mem_cost: 14,
}
In your terminal run firebase auth:import database.json --hash-algo=scrypt --rounds=8 --mem-cost=14 --hash-key=<long string of random characters> --salt-separator=<short string of random characters> --project=YOUR_PROJECT_NAME
. Note: I didn't use quotes for the strings and it worked out perfectly.
Test your authentication if it works on new environment. Might be obvious, but don't forget to change your firebaseConfig
to be on the new project :)
Edit:
To clarify on which Firebase Tools version it works:
$ firebase --version
7.6.1
It is now possible to export/import users in Firebase v3.x. All you have to do is install Firebase CLI (Firebase Tools), setup a folder on your machine representing tooling mirror for your Firebase project. (as simple as firebase init
in the appropriate folder)
To Export: auth:export
To Import: auth:import
Update: At the time I wrote this answer, given example in link above for auth:import
has 2 pieces missing: hash key
and salt separator
, which you can ask from customer support. Maybe they share it with tools or from console in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With