Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase import users from existing app

Tags:

firebase

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.

like image 605
Harry Avatar asked Apr 17 '13 06:04

Harry


People also ask

How do I import user accounts into a firebase project?

// ... 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.

What is the firebase admin SDK?

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:

How to import users in bulk to Firebase authentication with elevated privileges?

The Firebase Admin SDK provides the auth.importUsers () API for importing users in bulk to Firebase Authentication with elevated privileges.

What are the benefits of using Firebase integration?

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).


3 Answers

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.

like image 118
Rob DiMarco Avatar answered Sep 21 '22 19:09

Rob DiMarco


Update as of 11/2019

  1. 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.

  2. 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).

  3. Export your emails and password by using firebase auth:export database.json --project projectName.

  4. Now firebase logout and firebase login to the account where you want to import.

  5. 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,
}
  1. 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.

  2. 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
like image 22
Daniel Danielecki Avatar answered Sep 18 '22 19:09

Daniel Danielecki


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.

like image 36
Bogac Avatar answered Sep 19 '22 19:09

Bogac