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
73 changes: 46 additions & 27 deletions FirebaseAuth/Tests/Sample/Sample/MainViewController+Email.m
Original file line number Diff line number Diff line change
Expand Up @@ -133,36 +133,55 @@ - (void)signInEmailPassword {
}
[self showTextInputPromptWithMessage:[NSString stringWithFormat:@"Select factor to sign in\n%@", displayNameString]
completionBlock:^(BOOL userPressedOK, NSString *_Nullable displayName) {
FIRPhoneMultiFactorInfo* selectedHint;
FIRMultiFactorInfo* selectedHint;
for (FIRMultiFactorInfo *tmpFactorInfo in resolver.hints) {
if ([displayName isEqualToString:tmpFactorInfo.displayName]) {
selectedHint = (FIRPhoneMultiFactorInfo *)tmpFactorInfo;
selectedHint = tmpFactorInfo;
}
}
[FIRPhoneAuthProvider.provider
verifyPhoneNumberWithMultiFactorInfo:selectedHint
UIDelegate:nil
multiFactorSession:resolver.session
completion:^(NSString * _Nullable verificationID, NSError * _Nullable error) {
if (error) {
[self logFailure:@"Multi factor start sign in failed." error:error];
} else {
[self showTextInputPromptWithMessage:[NSString stringWithFormat:@"Verification code for %@", selectedHint.displayName]
completionBlock:^(BOOL userPressedOK, NSString *_Nullable verificationCode) {
FIRPhoneAuthCredential *credential =
[[FIRPhoneAuthProvider provider] credentialWithVerificationID:verificationID
verificationCode:verificationCode];
FIRMultiFactorAssertion *assertion = [FIRPhoneMultiFactorGenerator assertionWithCredential:credential];
[resolver resolveSignInWithAssertion:assertion completion:^(FIRAuthDataResult * _Nullable authResult, NSError * _Nullable error) {
if (error) {
[self logFailure:@"Multi factor finalize sign in failed." error:error];
} else {
[self logSuccess:@"Multi factor finalize sign in succeeded."];
}
}];
}];
}
}];
if ([selectedHint.factorID isEqualToString:@"phone"]) {
[FIRPhoneAuthProvider.provider
verifyPhoneNumberWithMultiFactorInfo:(FIRPhoneMultiFactorInfo *)selectedHint
UIDelegate:nil
multiFactorSession:resolver.session
completion:^(NSString * _Nullable verificationID, NSError * _Nullable error) {
if (error) {
[self logFailure:@"Multi factor start sign in failed." error:error];
} else {
[self showTextInputPromptWithMessage:[NSString stringWithFormat:@"Verification code for %@", selectedHint.displayName]
completionBlock:^(BOOL userPressedOK, NSString *_Nullable verificationCode) {
FIRPhoneAuthCredential *credential =
[[FIRPhoneAuthProvider provider] credentialWithVerificationID:verificationID
verificationCode:verificationCode];
FIRMultiFactorAssertion *assertion = [FIRPhoneMultiFactorGenerator assertionWithCredential:credential];
[resolver resolveSignInWithAssertion:assertion completion:^(FIRAuthDataResult * _Nullable authResult, NSError * _Nullable error) {
if (error) {
[self logFailure:@"Phone Multi factor finalize sign in failed." error:error];
} else {
[self logSuccess:@"Phone Multi factor finalize sign in succeeded."];
}
}];
}];
}
}];
} else if ([selectedHint.factorID isEqualToString:@"totp"]) {
[self showTextInputPromptWithMessage:[NSString stringWithFormat:@"TOTP Verification code for %@", selectedHint.displayName]
completionBlock:^(BOOL userPressedOK, NSString *_Nullable oneTimePassword) {
FIRMultiFactorAssertion *assertion = [FIRTOTPMultiFactorGenerator assertionForSignInWithEnrollmentID:selectedHint.UID oneTimePassword:oneTimePassword];
[resolver resolveSignInWithAssertion:assertion
completion:^(FIRAuthDataResult *_Nullable authResult,
NSError *_Nullable error) {
if (error) {
[self logFailure:@"TOTP Multi factor sign in failed." error:error];
} else {
[self logSuccess:@"TOTP Multi factor sign in succeeded."];
}
}];
}];
}
else {
[self log:[NSString stringWithFormat:@"Multi factor sign in does not support factor ID: %@", selectedHint.factorID]];
}
}];
} else {
[self logFailure:@"sign-in with Email/Password failed" error:error];
Expand All @@ -174,8 +193,8 @@ - (void)signInEmailPassword {
}];
}];
}];
}];
}];
}];
}

- (void)linkWithEmailPassword {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ - (void)phoneEnroll {
completionBlock:^(BOOL userPressedOK, NSString *_Nullable phoneNumber) {
[user.multiFactor
getSessionWithCompletion:^(FIRMultiFactorSession *_Nullable session, NSError *_Nullable error) {
// this is the step verfication code has been send to the phone number along with validating the number
[FIRPhoneAuthProvider.provider verifyPhoneNumber:phoneNumber
UIDelegate:nil
multiFactorSession:session
Expand Down