@@ -68,6 +68,10 @@ type multiFactorInfoResponse struct {
68
68
EnrolledAt string `json:"enrolledAt,omitempty"`
69
69
}
70
70
71
+ type multiFactorEnrollments struct {
72
+ Enrollments []* multiFactorInfoResponse `json:"enrollments"`
73
+ }
74
+
71
75
// MultiFactorInfo describes a user enrolled second phone factor.
72
76
// TODO : convert PhoneNumber to PhoneMultiFactorInfo struct
73
77
type MultiFactorInfo struct {
@@ -166,18 +170,19 @@ func (u *UserToCreate) set(key string, value interface{}) *UserToCreate {
166
170
167
171
// Converts a client format second factor object to server format.
168
172
func convertMultiFactorInfoToServerFormat (mfaInfo MultiFactorInfo ) (multiFactorInfoResponse , error ) {
169
- var authFactorInfo multiFactorInfoResponse
173
+ authFactorInfo := multiFactorInfoResponse { DisplayName : mfaInfo . DisplayName }
170
174
if mfaInfo .EnrollmentTimestamp != 0 {
171
175
authFactorInfo .EnrolledAt = time .Unix (mfaInfo .EnrollmentTimestamp , 0 ).Format ("2006-01-02T15:04:05Z07:00Z" )
172
176
}
177
+ if mfaInfo .UID != "" {
178
+ authFactorInfo .MFAEnrollmentID = mfaInfo .UID
179
+ }
173
180
if mfaInfo .FactorID == phoneMultiFactorID {
174
181
authFactorInfo .PhoneInfo = mfaInfo .PhoneNumber
175
- authFactorInfo .DisplayName = mfaInfo .DisplayName
176
- authFactorInfo .MFAEnrollmentID = mfaInfo .UID
177
182
return authFactorInfo , nil
178
183
}
179
184
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 ))
181
186
}
182
187
183
188
func (u * UserToCreate ) validatedRequest () (map [string ]interface {}, error ) {
@@ -333,7 +338,9 @@ func (u *UserToUpdate) validatedRequest() (map[string]interface{}, error) {
333
338
if err != nil {
334
339
return nil , err
335
340
}
336
- req ["mfaInfo" ] = mfaInfo
341
+
342
+ // https://cloud.google.com/identity-platform/docs/reference/rest/v1/accounts/update
343
+ req ["mfa" ] = multiFactorEnrollments {mfaInfo }
337
344
} else {
338
345
req [k ] = v
339
346
}
@@ -665,9 +672,6 @@ func validateAndFormatMfaSettings(mfaSettings MultiFactorSettings, methodType st
665
672
return nil , fmt .Errorf ("\" uid\" is not supported when adding second factors via \" createUser()\" " )
666
673
}
667
674
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
- }
671
675
default :
672
676
return nil , fmt .Errorf ("unsupported methodType: %s" , methodType )
673
677
}
0 commit comments