Hi!
I'm trying to import users from an older project which uses IdentityServer4 to manage authentification. I've tried simple examples to import user, but none would work. (I'm not even at a stage where I could import old users).
I've tried the following:
it("should import user correctly",
async () =>
{
const salt = crypto.
randomBytes(16);
const rounds =
10000;
const passwordStr =
"Test123();";
const email =
"tes...@test.com";
const password = crypto.
pbkdf2Sync(Buffer.
from(passwordStr,
"utf-8"),
salt,
rounds,
32,
"sha256");
const importResult =
await getAuth().
importUsers(
[{ email,
passwordHash:
password,
passwordSalt:
salt,
uid:
"123456" }],
{
hash:
{ algorithm:
"PBKDF2_SHA256",
rounds },
},
);
expect(importResult.
successCount).
toBe(1);
const body =
{ email,
password:
passwordStr };
const response =
await fetch(
"http://localhost:9099/identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=asdf",
{
method:
"post",
body:
JSON.
stringify(body),
headers:
{ "Content-Type":
"application/json" },
},
);
expect(response.
status).
toBe(200);
});
it("should import user correctly 2",
async () =>
{
const salt = crypto.
randomBytes(16);
const rounds =
10;
const passwordStr =
"Test123();";
const email =
"tes...@test.com";
const password = bcrypt.
hashSync(passwordStr,
rounds);
const importResult =
await getAuth().
importUsers([{ email,
passwordHash:
Buffer.
from(password),
uid:
"123456" }],
{
hash:
{ algorithm:
"BCRYPT" },
});
expect(importResult.
successCount).
toBe(1);
const body =
{ email,
password:
passwordStr };
const response =
await axios
({
url:
"http://127.0.0.1:9099/identitytoolkit.googleapis.com/v1/accounts:signInWithPassword",
params:
{ key:
"asdf" },
data:
body,
method:
"post",
validateStatus:
() =>
true,
});
console.
log(response.data
);
expect(response.status
).
toBe(200);
});
I would need to use PBKDF2_SHA256 but since that was not working I've tried bcrypt but that's not working either. I was trying to import it in the emulator and also tried a real project - nothing works.
I've also tried to import users using the cli (I found that code on Stackoverflow, but it looks finde?)
{
"users":
[
{
"localId":
"166666",
"email":
"166...@qq.com",
"emailVerified":
false,
"passwordHash":
"5NL5SaQBwE6c0L1BDjHW+BtBOXQVH8RYwY0tGGw3khk=",
"createdAt":
"1613525311156",
"lastSignedInAt":
"1613525311156",
"salt":
"c2FsdA==",
"providerUserInfo":
[]
}
]
}
using firebase auth:import test.json --rounds=1 --hash-algo=SHA256 --hash-input-order=PASSWORD_FIRST
I can always see the users in the dashboard, but when trying to sign in, with either a post request or Firebase Swift, it always would return an error stating the password is incorrect