firebase / firebase-admin-go

Firebase Admin Go SDK
Apache License 2.0
1.14k stars 247 forks source link

BUG: UpdateUser() is not able to update MFA #529

Closed brokeyourbike closed 1 year ago

brokeyourbike commented 1 year ago

Describe your environment

Describe the problem

It's not possible to update multi factor enrollments with UpdateUser() function. Create and update API requests have different structure when we speaking about MFA (don't know who thought it will be cool to do that). It's also not required to pass fields like UID or DisplayName when updating or creating MFA.

We can see the valid implementation in the firebase-admin-node repository

Steps to reproduce:

  1. Create user (or have existing firebase user) without MFA
  2. Try to add MFA with UpdateUser
  3. Nothing will happen, used will not have MFA after update

Relevant Code:

// 1. Create user
createParams := (&auth.UserToCreate{}).
        UID("01GM6YCBT7T0VNPNTCP44S7E8G").
        Email("john@doe.com").
        EmailVerified(true).
        Password("secret").
        DisplayName("John Doe").
        Disabled(false).
                MFASettings(auth.MultiFactorSettings{EnrolledFactors: nil})

user, err := firebaseAuth.CreateUser(ctx, params)
require.NoError(t, err)

// 2. Update user
updateParams := (&auth.UserToUpdate{}).
        MFASettings(auth.MultiFactorSettings{
            EnrolledFactors: []*auth.MultiFactorInfo{{
                                // problems will arise even on this stage
                                // because library things that it's required to pass UID and DisplayName
                FactorID:    "phone",
                PhoneNumber: "+16505557348",
            }},
        })

user, err = firebaseAuth.UpdateUser(ctx, user.UID, params)
assert.NoError(t, err)
assert.Len(t, user.MultiFactor.EnrolledFactors, 1)
pragatimodi commented 1 year ago

Since this PR has been merged, marking this issue as closed. Thanks!