@@ -68,6 +68,10 @@ type multiFactorInfoResponse struct {
6868 EnrolledAt string `json:"enrolledAt,omitempty"`
6969}
7070
71+ type multiFactorEnrollments struct {
72+ Enrollments []* multiFactorInfoResponse `json:"enrollments"`
73+ }
74+
7175// MultiFactorInfo describes a user enrolled second phone factor.
7276// TODO : convert PhoneNumber to PhoneMultiFactorInfo struct
7377type MultiFactorInfo struct {
@@ -166,18 +170,19 @@ func (u *UserToCreate) set(key string, value interface{}) *UserToCreate {
166170
167171// Converts a client format second factor object to server format.
168172func convertMultiFactorInfoToServerFormat (mfaInfo MultiFactorInfo ) (multiFactorInfoResponse , error ) {
169- var authFactorInfo multiFactorInfoResponse
173+ authFactorInfo := multiFactorInfoResponse { DisplayName : mfaInfo . DisplayName }
170174 if mfaInfo .EnrollmentTimestamp != 0 {
171175 authFactorInfo .EnrolledAt = time .Unix (mfaInfo .EnrollmentTimestamp , 0 ).Format ("2006-01-02T15:04:05Z07:00Z" )
172176 }
177+ if mfaInfo .UID != "" {
178+ authFactorInfo .MFAEnrollmentID = mfaInfo .UID
179+ }
173180 if mfaInfo .FactorID == phoneMultiFactorID {
174181 authFactorInfo .PhoneInfo = mfaInfo .PhoneNumber
175- authFactorInfo .DisplayName = mfaInfo .DisplayName
176- authFactorInfo .MFAEnrollmentID = mfaInfo .UID
177182 return authFactorInfo , nil
178183 }
179184 out , _ := json .Marshal (mfaInfo )
180- return multiFactorInfoResponse {}, fmt .Errorf ("Unsupported second factor %s provided" , string (out ))
185+ return multiFactorInfoResponse {}, fmt .Errorf ("unsupported second factor %s provided" , string (out ))
181186}
182187
183188func (u * UserToCreate ) validatedRequest () (map [string ]interface {}, error ) {
@@ -333,7 +338,9 @@ func (u *UserToUpdate) validatedRequest() (map[string]interface{}, error) {
333338 if err != nil {
334339 return nil , err
335340 }
336- req ["mfaInfo" ] = mfaInfo
341+
342+ // https://cloud.google.com/identity-platform/docs/reference/rest/v1/accounts/update
343+ req ["mfa" ] = multiFactorEnrollments {mfaInfo }
337344 } else {
338345 req [k ] = v
339346 }
@@ -665,9 +672,6 @@ func validateAndFormatMfaSettings(mfaSettings MultiFactorSettings, methodType st
665672 return nil , fmt .Errorf ("\" uid\" is not supported when adding second factors via \" createUser()\" " )
666673 }
667674 case updateUserMethod :
668- if multiFactorInfo .UID == "" {
669- return nil , fmt .Errorf ("the second factor \" uid\" must be a valid non-empty string when adding second factors via \" updateUser()\" " )
670- }
671675 default :
672676 return nil , fmt .Errorf ("unsupported methodType: %s" , methodType )
673677 }
0 commit comments