Skip to content

Commit 26075af

Browse files
author
chuanr
authored
Fix a bug where phone multi factor id is not correctly retrieved (#10061)
1 parent 9b4c200 commit 26075af

File tree

6 files changed

+58
-8
lines changed

6 files changed

+58
-8
lines changed

FirebaseAuth/Sources/Backend/RPC/Proto/FIRAuthProtoMFAEnrollment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN
2020

2121
@interface FIRAuthProtoMFAEnrollment : NSObject <FIRAuthProto>
2222

23-
@property(nonatomic, copy, readonly, nullable) NSString *MFAValue;
23+
@property(nonatomic, copy, readonly, nullable) NSString *phoneInfo;
2424

2525
@property(nonatomic, copy, readonly, nullable) NSString *MFAEnrollmentID;
2626

FirebaseAuth/Sources/Backend/RPC/Proto/FIRAuthProtoMFAEnrollment.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary {
2424
self = [super init];
2525
if (self) {
2626
if (dictionary[@"phoneInfo"]) {
27-
_MFAValue = dictionary[@"phoneInfo"];
27+
_phoneInfo = dictionary[@"phoneInfo"];
2828
}
2929
_MFAEnrollmentID = dictionary[@"mfaEnrollmentId"];
3030
_displayName = dictionary[@"displayName"];

FirebaseAuth/Sources/MultiFactor/FIRMultiFactor.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
#import "FirebaseAuth/Sources/AuthProvider/Phone/FIRPhoneAuthCredential_Internal.h"
3434
#import "FirebaseAuth/Sources/MultiFactor/Phone/FIRPhoneMultiFactorAssertion+Internal.h"
35+
#import "FirebaseAuth/Sources/MultiFactor/Phone/FIRPhoneMultiFactorInfo+Internal.h"
36+
3537
#endif
3638

3739
NS_ASSUME_NONNULL_BEGIN
@@ -155,9 +157,11 @@ - (instancetype)initWithMFAEnrollments:(NSArray<FIRAuthProtoMFAEnrollment *> *)M
155157
if (self) {
156158
NSMutableArray<FIRMultiFactorInfo *> *multiFactorInfoArray = [[NSMutableArray alloc] init];
157159
for (FIRAuthProtoMFAEnrollment *MFAEnrollment in MFAEnrollments) {
158-
FIRMultiFactorInfo *multiFactorInfo =
159-
[[FIRMultiFactorInfo alloc] initWithProto:MFAEnrollment];
160-
[multiFactorInfoArray addObject:multiFactorInfo];
160+
if (MFAEnrollment.phoneInfo) {
161+
FIRMultiFactorInfo *multiFactorInfo =
162+
[[FIRPhoneMultiFactorInfo alloc] initWithProto:MFAEnrollment];
163+
[multiFactorInfoArray addObject:multiFactorInfo];
164+
}
161165
}
162166
_enrolledFactors = [multiFactorInfoArray copy];
163167
}

FirebaseAuth/Sources/MultiFactor/FIRMultiFactorConstants.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121

2222
#pragma mark - Multi Factor ID constants
2323

24-
NSString *const FIRPhoneMultiFactorID = @"1";
24+
NSString *const FIRPhoneMultiFactorID = @"phone";
2525

2626
#endif

FirebaseAuth/Sources/MultiFactor/Phone/FIRPhoneMultiFactorInfo.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ - (instancetype)initWithProto:(FIRAuthProtoMFAEnrollment *)proto {
3131
self = [super initWithProto:proto];
3232
if (self) {
3333
_factorID = FIRPhoneMultiFactorID;
34-
_phoneNumber = proto.MFAValue;
34+
_phoneNumber = proto.phoneInfo;
3535
}
3636
return self;
3737
}

FirebaseAuth/Tests/Unit/FIRUserTests.m

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,26 @@
363363
*/
364364
static const NSTimeInterval kExpectationTimeout = 2;
365365

366+
/** @var kPhoneInfo
367+
@brief The mock multi factor phone info.
368+
*/
369+
static NSString *const kPhoneInfo = @"+15555555555";
370+
371+
/** @var kEnrollmentID
372+
@brief The mock multi factor enrollment ID.
373+
*/
374+
static NSString *const kEnrollmentID = @"mockEnrollmentID";
375+
376+
/** @var kDisplayName
377+
@brief The mock multi factor display name.
378+
*/
379+
static NSString *const kDisplayName = @"mockDisplayName";
380+
381+
/** @var kEnrolledAt
382+
@brief The mock multi factor enroll at date.
383+
*/
384+
static NSString *const kEnrolledAt = @"2022-08-01T18:31:15.426458Z";
385+
366386
/** @extention FIRSecureTokenService
367387
@brief Extends the FIRSecureTokenService class to expose one private method for testing only.
368388
*/
@@ -464,6 +484,13 @@ - (void)testUserPropertiesAndNSSecureCoding {
464484
];
465485
OCMStub([mockGetAccountInfoResponseUser providerUserInfo]).andReturn(providerUserInfos);
466486
OCMStub([mockGetAccountInfoResponseUser passwordHash]).andReturn(kPasswordHash);
487+
FIRAuthProtoMFAEnrollment *enrollment = [[FIRAuthProtoMFAEnrollment alloc] initWithDictionary:@{
488+
@"phoneInfo" : kPhoneInfo,
489+
@"mfaEnrollmentId" : kEnrollmentID,
490+
@"displayName" : kDisplayName,
491+
@"enrolledAt" : kEnrolledAt
492+
}];
493+
OCMStub([mockGetAccountInfoResponseUser MFAEnrollments]).andReturn(@[ enrollment ]);
467494

468495
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
469496
[self
@@ -640,8 +667,27 @@ - (void)testUserPropertiesAndNSSecureCoding {
640667
XCTAssertEqualObjects(
641668
unarchivedPhoneUserInfo.phoneNumber,
642669
phoneUserInfo.phoneNumber);
643-
#endif
644670

671+
// Verify FIRMultiFactorInfo properties.
672+
XCTAssertEqualObjects(
673+
user.multiFactor.enrolledFactors[0].factorID,
674+
FIRPhoneMultiFactorID);
675+
XCTAssertEqualObjects(
676+
user.multiFactor.enrolledFactors[0].UID,
677+
kEnrollmentID);
678+
XCTAssertEqualObjects(
679+
user.multiFactor.enrolledFactors[0].displayName,
680+
kDisplayName);
681+
NSDateFormatter *dateFormatter =
682+
[[NSDateFormatter alloc] init];
683+
[dateFormatter
684+
setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
685+
NSDate *date =
686+
[dateFormatter dateFromString:kEnrolledAt];
687+
XCTAssertEqualObjects(
688+
user.multiFactor.enrolledFactors[0].enrollmentDate,
689+
date);
690+
#endif
645691
[expectation fulfill];
646692
}];
647693
[self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil];

0 commit comments

Comments
 (0)