How to compare a Firebase/scrypt hashed password for Basic Authentication in Firebase-admin?

Viewed 81

I want to authenticate calls to our firebase-functions endpoint using a Basic authorization header that contains a uid & password. I thought Firebase was using bcrypt, so I had planned to use bcrypt.compare. Is there a way to do this for whatever version of scrypt Firebase uses? Users were created using admin.auth().createUser({...}).

I was testing the bcrypt plan with this (a known uid & password are in req.body):

const bcrypt = require("bcrypt");
app.post("/hash", async (req, res) => {
    const listUsersResult = await admin.auth().listUsers();
    
    const userResult = listUsersResult.users[listUsersResult.users.findIndex((userRecord) => userRecord.uid == req.body.uid)];
    const passhash = userResult.passwordHash;

    const result = await bcrypt.compare(req.body.password, passhash);
    return res.status(200).send(`compare ${req.body.password} and ${passhash}: ${result}`);
});
0 Answers
Related