Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(auth): Allow to update MFA #530

Merged
merged 9 commits into from
Sep 6, 2023
Merged

fix(auth): Allow to update MFA #530

merged 9 commits into from
Sep 6, 2023

Conversation

brokeyourbike
Copy link
Contributor

@brokeyourbike brokeyourbike commented Dec 13, 2022

  • UpdateUser can update MFA
  • UID is not required when updating MFA
  • DisplayName is not required field

Fixes #529.

RELEASE NOTE: Allow updating multi factor enrollments in UpdateUser() API

@brokeyourbike
Copy link
Contributor Author

@lahirumaramba @hiranya911 👋

@prameshj
Copy link

Thanks for the fix!
@pragatimodi can you take a look too? This is a follow up to #511, the fields in updateUser expect "mfa" rather than "mfaInfo". Thanks!

@@ -170,14 +174,16 @@ func convertMultiFactorInfoToServerFormat(mfaInfo MultiFactorInfo) (multiFactorI
if mfaInfo.EnrollmentTimestamp != 0 {
authFactorInfo.EnrolledAt = time.Unix(mfaInfo.EnrollmentTimestamp, 0).Format("2006-01-02T15:04:05Z07:00Z")
}
if mfaInfo.UID != "" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since phone is the only factorId, is it ok to put this in the if block below?

Or is this to cover the case where a factorId is not specified?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be moved to the block bellow of course, but why we have the EnrollmentTimestamp at the top for example?

I just thought that UID will probably exist for every "factor", because we will need it when updating something, so it's safe to move it from the block

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. We will likely move it out of the if block when we add another MFA (like TOTP).

Similarly, DisplayName is a generic field too. So you could move that out too.

@@ -333,7 +339,7 @@ func (u *UserToUpdate) validatedRequest() (map[string]interface{}, error) {
if err != nil {
return nil, err
}
req["mfaInfo"] = mfaInfo
req["mfa"] = multiFactorEnrollments{mfaInfo}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can you link to the docs https://cloud.google.com/identity-platform/docs/reference/rest/v1/accounts/update for easy reference next time? Thanks!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nit: Please add this link as a code comment if possible.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not showing up in the diff yet.. otherwise lgtm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have added the link as you suggested @prameshj . Please take a look

auth/user_mgt.go Outdated
default:
return nil, fmt.Errorf("unsupported methodType: %s", methodType)
}
if err := validateDisplayName(multiFactorInfo.DisplayName); err != nil {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't we want to include a display name for a (new or existing) mfa option? Any downside to requiring this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only downside it that it's not really required from the API point of view

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be ok to require it on the SDK, since this field helps identify the MFA option easily. @lahirumaramba any thoughts?

@@ -894,17 +873,6 @@ func TestInvalidUpdateUser(t *testing.T) {
},
}),
`the second factor "phoneNumber" for "invalid" must be a non-empty E.164 standard compliant identifier string`,
}, {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would prefer to keep the test cases related to display name field being required.

@pragatimodi
Copy link
Contributor

Thanks for finding this fix!

@prameshj
Copy link

Thanks! I have one final nit, LGTM otherwise.

@lahirumaramba for final approval/merge.

@lahirumaramba lahirumaramba self-assigned this Mar 24, 2023
@brokeyourbike
Copy link
Contributor Author

can this be merged @lahirumaramba ?

@brokeyourbike
Copy link
Contributor Author

Hi team, can you please take a look at the PR. I have made the changes as requested. @prameshj @lahirumaramba

@pragatimodi pragatimodi requested a review from prameshj May 31, 2023 16:02
@brokeyourbike
Copy link
Contributor Author

Hello team, can we please move forward with this PR? Let me know if there is anything I should do
@prameshj @pragatimodi @lahirumaramba

@prameshj
Copy link

Thanks for checking, Ivan! The changes look good to me. I think we only need @lahirumaramba to approve. Lahiru, can you help with this? Thanks!

@brokeyourbike
Copy link
Contributor Author

brokeyourbike commented Aug 14, 2023

Thank you for the update @prameshj
@lahirumaramba can you please help with reviewing this PR? It's been in this state for over 6 month now

@brokeyourbike
Copy link
Contributor Author

Are my proposed changes outdated and do not comply with expected release? Should I create a new PR and revisit what was done?

Please give at least some direction @prameshj @pragatimodi @lahirumaramba , thanks.

@lahirumaramba
Copy link
Member

Thanks folks! We will include this in the next release.

@lahirumaramba lahirumaramba changed the title Allow to update MFA fix(auth): Allow to update MFA Sep 6, 2023
@lahirumaramba lahirumaramba merged commit 2ec220a into firebase:dev Sep 6, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants