0
votes

I'm trying to migrate users (using [email protected]) into firebase auth, following this guide: https://firebase.google.com/docs/auth/admin/import-users#import_users_with_md5_sha_and_pbkdf_hashed_passwords

In the old system, the passwords were hashed in php:

$Password = hash('sha256', $Password);

I'm running this code to import the users into firebase:

const res = await admin.auth().importUsers([{
  uid: 'ABC123',
  email: '[email protected]',
  passwordHash: Buffer.from('5457ae6b180556bc65b423ba3a36124ec44f6cbec7da84e483daa2a46dec3f97') 
}], {
  hash: {
    algorithm: 'SHA256',
    rounds: 1
  }
});

The import succeeds, but I can't login using the same password (LeeT1337).

Also when I export all users, running

firebase auth:export auth-export.json --format json

the imported user, unlike all others, doesn't have a passwordHash property.

I've also tried base64-encoding the hash first (since it's suggested in old stack posts, but not in the docs anymore).

Alternativlely I've tried importing via the cli ([email protected]) with:

{
  "users": [
    {
      "localId": "ABC123",
      "email": "[email protected]",
      "passwordHash": "NTQ1N2FlNmIxODA1NTZiYzY1YjQyM2JhM2EzNjEyNGVjNDRmNmNiZWM3ZGE4NGU0ODNkYWEyYTQ2ZGVjM2Y5Nw=="
    }
  ]
}

and

firebase auth:import users-for-import.json --hash-algo=SHA256 --rounds=1

but got the same result: Import works, login doesn't.

1

1 Answers

1
votes
Buffer.from('5457ae6b180556bc65b423ba3a36124ec44f6cbec7da84e483daa2a46dec3f97')

needs to be changed to

Buffer.from('5457ae6b180556bc65b423ba3a36124ec44f6cbec7da84e483daa2a46dec3f97', 'hex')