Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set hash-key option for auth:import after default auth:export in firebase?

Tags:

I've got my users exported the in CLI:

firebase auth:export my_users.json

The passwords in the exported file should be hashed with SCRYPT, because as the documentation states:

auth:export command only exports passwords hashed using the scrypt algorithm, which is used by the Firebase backend. Account records with passwords hashed using other algorithms are exported with empty passwordHash and salt fields. Projects might have passwords hashed with other algorithms after importing user records from a file, since passwords are only re-hashed with scrypt when an imported user signs in for the first time

My hash-key and salt fields are not empty in the result. Also, I know that all my users signed in at least once.

Now, when I try to import my_users.json:

firebase auth:import --hash-algo=SCRYPT --rounds=1 my_users.json

I get the following error:

Must provide hash key(base64 encoded) for hash algorithm SCRYPT

But what should I set --hash-key to, since the auth:export command did not take any parameters? ...

Thanks in advance

like image 1000
ezmegy Avatar asked Jul 30 '17 21:07

ezmegy


People also ask

Does Firebase automatically hash passwords?

By default, Firebase uses a modified Firebase version of the scrypt hashing algorithm to store passwords. Importing passwords hashed with modified scrypt is useful for migrating users from another existing Firebase project.

What does Firebase auth () currentUser return?

console. log(firebase. auth(). currentUser) // This returns null console.

What is FirebaseAuth getInstance ()?

getInstance() Returns an instance of this class corresponding to the default FirebaseApp instance. static FirebaseAuth. getInstance(FirebaseApp firebaseApp) Returns an instance of this class corresponding to the given FirebaseApp instance.

How do I import Auth from Firebase app?

Import firebase and firebase/authimport firebase from "firebase/app"; import "firebase/auth"; Place a FirebaseAuthProvider component at the top level of your app. ( anywhere as long as it's above the other Auth components ). Then use any of the other components anywhere in your component tree.


1 Answers

So you can now get the hash key and the salt info from the firebase console GUI. I had to enter incognito mode in chrome for some reason (firebase support suggested this).

I could then log into my firebase console in the incognito browser.

(Note that you need to use the firebase instance that you are copying users from, not the one that you are copying users to)

You click on Authentication -> Users and then click on the three vertical dots next to the reload button and a popup menu will show up with a single menu item: "Password hash parameters".

password hash parameters

Click on this menu item and all of the settings you need for doing the firebase auth:import command will show up. Here's what I see:

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,
}

I can then do the command successfully

firebase auth:import ./users.json --hash-algo=scrypt --rounds=8 --mem-cost=14 --hash-key=<long string of random characters> --salt-separator=<short string of random characters>
like image 101
Geoffrey Wall Avatar answered Oct 02 '22 12:10

Geoffrey Wall