Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN

@interface FIRAuthProtoMFAEnrollment : NSObject <FIRAuthProto>

@property(nonatomic, copy, readonly, nullable) NSString *MFAValue;
@property(nonatomic, copy, readonly, nullable) NSString *phoneInfo;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary {
self = [super init];
if (self) {
if (dictionary[@"phoneInfo"]) {
_MFAValue = dictionary[@"phoneInfo"];
_phoneInfo = dictionary[@"phoneInfo"];
}
_MFAEnrollmentID = dictionary[@"mfaEnrollmentId"];
_displayName = dictionary[@"displayName"];
Expand Down
10 changes: 7 additions & 3 deletions FirebaseAuth/Sources/MultiFactor/FIRMultiFactor.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#import "FirebaseAuth/Sources/AuthProvider/Phone/FIRPhoneAuthCredential_Internal.h"
#import "FirebaseAuth/Sources/MultiFactor/Phone/FIRPhoneMultiFactorAssertion+Internal.h"
#import "FirebaseAuth/Sources/MultiFactor/Phone/FIRPhoneMultiFactorInfo+Internal.h"

#endif

NS_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -155,9 +157,11 @@ - (instancetype)initWithMFAEnrollments:(NSArray<FIRAuthProtoMFAEnrollment *> *)M
if (self) {
NSMutableArray<FIRMultiFactorInfo *> *multiFactorInfoArray = [[NSMutableArray alloc] init];
for (FIRAuthProtoMFAEnrollment *MFAEnrollment in MFAEnrollments) {
FIRMultiFactorInfo *multiFactorInfo =
[[FIRMultiFactorInfo alloc] initWithProto:MFAEnrollment];
[multiFactorInfoArray addObject:multiFactorInfo];
if (MFAEnrollment.phoneInfo) {
FIRMultiFactorInfo *multiFactorInfo =
[[FIRPhoneMultiFactorInfo alloc] initWithProto:MFAEnrollment];
[multiFactorInfoArray addObject:multiFactorInfo];
}
}
_enrolledFactors = [multiFactorInfoArray copy];
}
Expand Down
2 changes: 1 addition & 1 deletion FirebaseAuth/Sources/MultiFactor/FIRMultiFactorConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@

#pragma mark - Multi Factor ID constants

NSString *const FIRPhoneMultiFactorID = @"1";
NSString *const FIRPhoneMultiFactorID = @"phone";

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ - (instancetype)initWithProto:(FIRAuthProtoMFAEnrollment *)proto {
self = [super initWithProto:proto];
if (self) {
_factorID = FIRPhoneMultiFactorID;
_phoneNumber = proto.MFAValue;
_phoneNumber = proto.phoneInfo;
}
return self;
}
Expand Down
48 changes: 47 additions & 1 deletion FirebaseAuth/Tests/Unit/FIRUserTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,26 @@
*/
static const NSTimeInterval kExpectationTimeout = 2;

/** @var kPhoneInfo
@brief The mock multi factor phone info.
*/
static NSString *const kPhoneInfo = @"+15555555555";

/** @var kEnrollmentID
@brief The mock multi factor enrollment ID.
*/
static NSString *const kEnrollmentID = @"mockEnrollmentID";

/** @var kDisplayName
@brief The mock multi factor display name.
*/
static NSString *const kDisplayName = @"mockDisplayName";

/** @var kEnrolledAt
@brief The mock multi factor enroll at date.
*/
static NSString *const kEnrolledAt = @"2022-08-01T18:31:15.426458Z";

/** @extention FIRSecureTokenService
@brief Extends the FIRSecureTokenService class to expose one private method for testing only.
*/
Expand Down Expand Up @@ -464,6 +484,13 @@ - (void)testUserPropertiesAndNSSecureCoding {
];
OCMStub([mockGetAccountInfoResponseUser providerUserInfo]).andReturn(providerUserInfos);
OCMStub([mockGetAccountInfoResponseUser passwordHash]).andReturn(kPasswordHash);
FIRAuthProtoMFAEnrollment *enrollment = [[FIRAuthProtoMFAEnrollment alloc] initWithDictionary:@{
@"phoneInfo" : kPhoneInfo,
@"mfaEnrollmentId" : kEnrollmentID,
@"displayName" : kDisplayName,
@"enrolledAt" : kEnrolledAt
}];
OCMStub([mockGetAccountInfoResponseUser MFAEnrollments]).andReturn(@[ enrollment ]);

XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
[self
Expand Down Expand Up @@ -640,8 +667,27 @@ - (void)testUserPropertiesAndNSSecureCoding {
XCTAssertEqualObjects(
unarchivedPhoneUserInfo.phoneNumber,
phoneUserInfo.phoneNumber);
#endif

// Verify FIRMultiFactorInfo properties.
XCTAssertEqualObjects(
user.multiFactor.enrolledFactors[0].factorID,
FIRPhoneMultiFactorID);
XCTAssertEqualObjects(
user.multiFactor.enrolledFactors[0].UID,
kEnrollmentID);
XCTAssertEqualObjects(
user.multiFactor.enrolledFactors[0].displayName,
kDisplayName);
NSDateFormatter *dateFormatter =
[[NSDateFormatter alloc] init];
[dateFormatter
setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
NSDate *date =
[dateFormatter dateFromString:kEnrolledAt];
XCTAssertEqualObjects(
user.multiFactor.enrolledFactors[0].enrollmentDate,
date);
#endif
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil];
Expand Down