firebase-admin-node icon indicating copy to clipboard operation
firebase-admin-node copied to clipboard

Add support for importing users with totp second factor

Open pragatimodi opened this issue 1 year ago • 0 comments

No integration tests. Manually tested input

const users = [
  {
    uid: '3456',
    email: '[email protected]',
    emailVerified:true,
    multiFactor: {
      enrolledFactors: [
        {
          uid: 'enrolledSecondFactor1',
          phoneNumber: '+16505557348',
          displayName: "Spouse's phone number",
          factorId: 'phone',
          enrollmentTime: nowString,
        },
        {
          uid: 'enrolledSecondFactor2',
          phoneNumber: '+16505551000',
          factorId: 'phone',
        },
        {
          uid: 'enrolledSecondFactor3',
          enrollmentTime: nowString,
          displayName: 'displayNameTotp',
          totpInfo: {
            sharedSecretKey: 'VIAAQYSO37EKAWB2KAXEQ7EGUMLWI3P4',
          },
          factorId: 'totp',
        },
      ],
    },
  },
];

getAuth()
  .importUsers(users)
  .then((importedUsers) => {
    console.log(JSON.stringify(importedUsers));
  })
  .catch((error) => {
    console.error('Error importing users:', error);
  });

with result {"successCount":1,"failureCount":0,"errors":[]}

Further verified with console and getUser method that user has been imported successfully.

pragatimodi avatar Nov 08 '23 17:11 pragatimodi