428
428
*/
429
429
static NSString *const kAutoAccountLinking = @" Link with Google" ;
430
430
431
+ /* * @var kAutoPhoneNumberSignIn
432
+ @brief The button title for automated account linking.
433
+ */
434
+ static NSString *const kAutoPhoneNumberSignIn = @" Sign in With Phone Number" ;
435
+
431
436
/* * @var kGitHubSignInButtonText
432
437
@brief The button title for signing in with github.
433
438
*/
@@ -671,7 +676,7 @@ - (void)updateTable {
671
676
]],
672
677
[StaticContentTableViewSection sectionWithTitle: kPhoneAuthSectionTitle cells: @[
673
678
[StaticContentTableViewCell cellWithTitle: kPhoneNumberSignInReCaptchaTitle
674
- action: ^{ [weakSelf signInWithPhoneNumberRecaptcha ]; }],
679
+ action: ^{ [weakSelf signInWithPhoneNumberRecaptcha ];}],
675
680
[StaticContentTableViewCell cellWithTitle: kPhoneNumberSignInTitle
676
681
action: ^{ [weakSelf signInWithPhoneNumber ]; }],
677
682
[StaticContentTableViewCell cellWithTitle: kUpdatePhoneNumber
@@ -680,7 +685,7 @@ - (void)updateTable {
680
685
action: ^{ [weakSelf linkPhoneNumber ]; }],
681
686
[StaticContentTableViewCell cellWithTitle: kUnlinkPhoneNumber
682
687
action: ^{
683
- [weakSelf unlinkFromProvider: FIRPhoneAuthProviderID];
688
+ [weakSelf unlinkFromProvider: FIRPhoneAuthProviderID completion: nil ];
684
689
}],
685
690
]],
686
691
[StaticContentTableViewSection sectionWithTitle: kSectionTitleSignIn cells: @[
@@ -775,15 +780,15 @@ - (void)updateTable {
775
780
action: ^{ [weakSelf linkWithEmailPassword ]; }],
776
781
[StaticContentTableViewCell cellWithTitle: kUnlinkFromGoogle
777
782
action: ^{
778
- [weakSelf unlinkFromProvider: FIRGoogleAuthProviderID];
783
+ [weakSelf unlinkFromProvider: FIRGoogleAuthProviderID completion: nil ];
779
784
}],
780
785
[StaticContentTableViewCell cellWithTitle: kUnlinkFromFacebook
781
786
action: ^{
782
- [weakSelf unlinkFromProvider: FIRFacebookAuthProviderID ];
787
+ [weakSelf unlinkFromProvider: FIRGoogleAuthProviderID completion: nil ];
783
788
}],
784
789
[StaticContentTableViewCell cellWithTitle: kUnlinkFromEmailPassword
785
790
action: ^{
786
- [weakSelf unlinkFromProvider: FIREmailAuthProviderID ];
791
+ [weakSelf unlinkFromProvider: FIRGoogleAuthProviderID completion: nil ];
787
792
}]
788
793
]],
789
794
[StaticContentTableViewSection sectionWithTitle: kSectionTitleApp cells: @[
@@ -818,7 +823,9 @@ - (void)updateTable {
818
823
[StaticContentTableViewCell cellWithTitle: kAutoSignInAnonymously
819
824
action: ^{ [weakSelf automatedAnonymousSignIn ]; }],
820
825
[StaticContentTableViewCell cellWithTitle: kAutoAccountLinking
821
- action: ^{ [weakSelf automatedAccountLinking ]; }]
826
+ action: ^{ [weakSelf automatedAccountLinking ]; }],
827
+ [StaticContentTableViewCell cellWithTitle: kAutoPhoneNumberSignIn
828
+ action: ^{ [weakSelf automatedPhoneNumberSignIn ]; }]
822
829
]]
823
830
]];
824
831
}
@@ -1032,6 +1039,56 @@ - (void)automatedSignInFacebook {
1032
1039
}];
1033
1040
}
1034
1041
1042
+ /* * @fn automatedPhoneNumberSignIn
1043
+ @brief Automatically executes the manual test for sign-in with phone number.
1044
+ */
1045
+ - (void )automatedPhoneNumberSignIn {
1046
+ [self log: @" Automated phone number sign in" ];
1047
+ FIRAuth *auth = [AppManager auth ];
1048
+ if (!auth) {
1049
+ [self logFailedTest: @" Could not obtain auth object." ];
1050
+ return ;
1051
+ }
1052
+ [auth signOut: NULL ];
1053
+ [self log: @" INITIATING AUTOMATED MANUAL TEST FOR PHONE NUMBER SIGN IN:" ];
1054
+ [self commonPhoneNumberInputWithTitle: @" Phone for automation"
1055
+ Completion: ^(NSString *_Nullable phone) {
1056
+ [self signInWithPhoneNumberRecaptchaWithString: phone completion: ^(NSError *error){
1057
+ if (error) {
1058
+ [self logFailedTest: @" Could not sign in with phone number reCAPTCHA." ];
1059
+ }
1060
+ [self logSuccess: @" sign-in with phone number reCAPTCHA test succeeded." ];
1061
+ [auth signOut: NULL ];
1062
+ [self signInWithPhoneNumberRecaptchaWithString: phone completion: ^(NSError *error){
1063
+ if (error) {
1064
+ [self logFailedTest: @" Could not sign in with phone number reCAPTCHA." ];
1065
+ }
1066
+ [self logSuccess: @" second sign-in with phone number reCAPTCHA test succeeded." ];
1067
+ [self updatePhoneNumberWithString: phone completion: ^{
1068
+ if (error) {
1069
+ [self logFailedTest: @" Could not update phone number." ];
1070
+ }
1071
+ [self logSuccess: @" update phone number test succeeded." ];
1072
+ [self unlinkFromProvider: FIRPhoneAuthProviderID completion: ^ {
1073
+ if (error) {
1074
+ [self logFailedTest: @" Could not unlink phone number." ];
1075
+ }
1076
+ [self logSuccess: @" unlink phone number test succeeded." ];
1077
+ [self linkPhoneNumberWithString: phone completion: ^{
1078
+ if (error) {
1079
+ [self logFailedTest: @" Could not link phone number." ];
1080
+ }
1081
+ [self logSuccess: @" link phone number test succeeded." ];
1082
+ [self log: @" FINISHED AUTOMATED MANUAL TEST FOR PHONE NUMBER SIGN IN." ];
1083
+ }];
1084
+ }];
1085
+ }];
1086
+ }];
1087
+ }];
1088
+ }];
1089
+ }
1090
+
1091
+
1035
1092
/* * @fn automatedEmailSignUp
1036
1093
@brief Automatically executes the manual test for sign-up with email/password.
1037
1094
*/
@@ -2050,14 +2107,15 @@ - (void)showEmailPasswordDialogWithCompletion:(ShowEmailPasswordDialogCompletion
2050
2107
@brief Unlinks the current user from the provider with the specified provider ID.
2051
2108
@param provider The provider ID of the provider to unlink the current user's account from.
2052
2109
*/
2053
- - (void )unlinkFromProvider : (NSString *)provider {
2110
+ - (void )unlinkFromProvider : (NSString *)provider completion : ( void (^)( void )) completion {
2054
2111
[[self user ] unlinkFromProvider: provider
2055
2112
completion: ^(FIRUser *_Nullable user,
2056
2113
NSError *_Nullable error) {
2057
2114
if (error) {
2058
2115
[self logFailure: @" unlink auth provider failed" error: error];
2059
2116
} else {
2060
2117
[self logSuccess: @" unlink auth provider succeeded." ];
2118
+ if (completion) completion ();
2061
2119
}
2062
2120
[self showTypicalUIForUserUpdateResultsWithTitle: kUnlinkTitle error: error];
2063
2121
}];
@@ -2458,32 +2516,41 @@ - (void)signInWithPhoneNumber {
2458
2516
}];
2459
2517
}
2460
2518
2519
+ /* * @fn signInWithPhoneNumberRecaptchaWithString
2520
+ @brief Allows sign in with phone number using reCAPTCHA and completion.
2521
+ @param phoneNumber Number pass in string for automation.
2522
+ */
2523
+ - (void )signInWithPhoneNumberRecaptchaWithString : (NSString *_Nullable)phoneNumber
2524
+ completion : (void (^)(NSError *_Nullable))completion {
2525
+ [self showSpinner: ^{
2526
+ [[AppManager phoneAuthProvider ] verifyPhoneNumber: phoneNumber
2527
+ UIDelegate: nil
2528
+ completion: ^(NSString *_Nullable verificationID,
2529
+ NSError *_Nullable error) {
2530
+ [self hideSpinner: ^{
2531
+ if (error) {
2532
+ [self logFailure: @" failed to send verification code" error: error];
2533
+ [self showMessagePrompt: error.localizedDescription];
2534
+ return ;
2535
+ }
2536
+ [self logSuccess: @" Code sent" ];
2537
+ [self commonPhoneNumberInputWithTitle: @" Code"
2538
+ Completion: ^(NSString *_Nullable verificationCode) {
2539
+ [self commontPhoneVerificationWithVerificationID: verificationID
2540
+ verificationCode: verificationCode];
2541
+ if (completion) completion (nil );
2542
+ }];
2543
+ }];
2544
+ }];
2545
+ }];
2546
+ }
2547
+
2461
2548
/* * @fn signInWithPhoneNumberRecaptcha
2462
2549
@brief Allows sign in with phone number using reCAPTCHA
2463
2550
*/
2464
2551
- (void )signInWithPhoneNumberRecaptcha {
2465
2552
[self commonPhoneNumberInputWithTitle: @" Phone #" Completion: ^(NSString *_Nullable phone) {
2466
- [self showSpinner: ^{
2467
- [[AppManager phoneAuthProvider ] verifyPhoneNumber: phone
2468
- UIDelegate: nil
2469
- completion: ^(NSString *_Nullable verificationID,
2470
- NSError *_Nullable error) {
2471
- [self hideSpinner: ^{
2472
- if (error) {
2473
- [self logFailure: @" failed to send verification code" error: error];
2474
- [self showMessagePrompt: error.localizedDescription];
2475
- return ;
2476
- }
2477
- [self logSuccess: @" Code sent" ];
2478
-
2479
- [self commonPhoneNumberInputWithTitle: @" Code"
2480
- Completion: ^(NSString *_Nullable verificationCode) {
2481
- [self commontPhoneVerificationWithVerificationID: verificationID
2482
- verificationCode: verificationCode];
2483
- }];
2484
- }];
2485
- }];
2486
- }];
2553
+ [self signInWithPhoneNumberRecaptchaWithString: (phone) completion: nil ];
2487
2554
}];
2488
2555
}
2489
2556
@@ -2502,7 +2569,6 @@ - (void)commonPhoneNumberInputWithTitle:(NSString *)title
2502
2569
completion (phoneNumber);
2503
2570
}];
2504
2571
}
2505
-
2506
2572
/* * @fn commonPhoneNumberInputWithLabel:Completion
2507
2573
@brief Finishes the phone number verification flow.
2508
2574
@param verificationID The verificationID from the backend.
@@ -2528,69 +2594,75 @@ - (void)commontPhoneVerificationWithVerificationID:(NSString *)verificationID
2528
2594
}];
2529
2595
}
2530
2596
2531
- /* * @fn updatePhoneNumber
2597
+ /* * @fn updatePhoneNumberWithString
2532
2598
@brief Allows adding a verified phone number to the currently signed user.
2599
+ @param phoneNumber Number pass in string for automation.
2533
2600
*/
2534
- - (void )updatePhoneNumber {
2535
- [self showTextInputPromptWithMessage: @" Phone #:"
2536
- keyboardType: UIKeyboardTypePhonePad
2537
- completionBlock: ^(BOOL userPressedOK, NSString *_Nullable phoneNumber) {
2538
- if (!userPressedOK || !phoneNumber.length ) {
2539
- return ;
2540
- }
2541
- [self showSpinner: ^{
2542
- [[AppManager phoneAuthProvider ] verifyPhoneNumber: phoneNumber
2543
- UIDelegate: nil
2544
- completion: ^(NSString *_Nullable verificationID,
2545
- NSError *_Nullable error) {
2546
- if (error) {
2547
- [self logFailure: @" failed to send verification code" error: error];
2548
- [self showMessagePrompt: error.localizedDescription];
2549
- return ;
2550
- }
2551
- [self logSuccess: @" Code sent" ];
2552
-
2553
- [self showTextInputPromptWithMessage: @" Verification code:"
2554
- keyboardType: UIKeyboardTypeNumberPad
2555
- completionBlock: ^(BOOL userPressedOK,
2556
- NSString *_Nullable verificationCode) {
2557
- if (!userPressedOK || !verificationCode.length ) {
2558
- return ;
2559
- }
2560
- [self showSpinner: ^{
2561
- FIRPhoneAuthCredential *credential =
2562
- [[AppManager phoneAuthProvider ] credentialWithVerificationID: verificationID
2563
- verificationCode: verificationCode];
2564
- [[self user ] updatePhoneNumberCredential: credential
2565
- completion: ^(NSError *_Nullable error) {
2566
- if (error) {
2567
- [self logFailure: @" update phone number failed" error: error];
2568
- [self showMessagePrompt: error.localizedDescription];
2569
- } else {
2570
- [self logSuccess: @" update phone number succeeded." ];
2571
- }
2572
- }];
2573
- }];
2574
- }];
2575
- [self hideSpinner: ^{
2576
- [self showTypicalUIForUserUpdateResultsWithTitle: kCreateUserTitle error: error];
2601
+ - (void )updatePhoneNumberWithString : (NSString *_Nullable)phoneNumber
2602
+ completion : (void (^)(void ))completion {
2603
+ [self showSpinner: ^{
2604
+ [[AppManager phoneAuthProvider ] verifyPhoneNumber: phoneNumber
2605
+ UIDelegate: nil
2606
+ completion: ^(NSString *_Nullable verificationID,
2607
+ NSError *_Nullable error) {
2608
+ if (error) {
2609
+ [self logFailure: @" failed to send verification code" error: error];
2610
+ [self showMessagePrompt: error.localizedDescription];
2611
+ return ;
2612
+ }
2613
+ [self logSuccess: @" Code sent" ];
2614
+
2615
+ [self showTextInputPromptWithMessage: @" Verification code:"
2616
+ keyboardType: UIKeyboardTypeNumberPad
2617
+ completionBlock: ^(BOOL userPressedOK,
2618
+ NSString *_Nullable verificationCode) {
2619
+ if (!userPressedOK || !verificationCode.length ) {
2620
+ return ;
2621
+ }
2622
+ [self showSpinner: ^{
2623
+ FIRPhoneAuthCredential *credential =
2624
+ [[AppManager phoneAuthProvider ] credentialWithVerificationID: verificationID
2625
+ verificationCode: verificationCode];
2626
+ [[self user ] updatePhoneNumberCredential: credential
2627
+ completion: ^(NSError *_Nullable error) {
2628
+ if (error) {
2629
+ [self logFailure: @" update phone number failed" error: error];
2630
+ [self showMessagePrompt: error.localizedDescription];
2631
+ } else {
2632
+ [self logSuccess: @" update phone number succeeded." ];
2633
+ if (completion) completion ();
2634
+ }
2577
2635
}];
2578
2636
}];
2579
2637
}];
2638
+ [self hideSpinner: ^{
2639
+ [self showTypicalUIForUserUpdateResultsWithTitle: kCreateUserTitle error: error];
2640
+ }];
2580
2641
}];
2642
+ }];
2581
2643
}
2582
2644
2583
- /* * @fn linkPhoneNumber
2584
- @brief Allows linking a verified phone number to the currently signed user.
2645
+ /* * @fn updatePhoneNumber
2646
+ @brief Allows adding a verified phone number to the currently signed user via popup prompt .
2585
2647
*/
2586
- - (void )linkPhoneNumber {
2587
- [self showTextInputPromptWithMessage: @" Phone #:"
2648
+ - (void )updatePhoneNumber {
2649
+ [self showTextInputPromptWithMessage: @" Update Phone #:"
2588
2650
keyboardType: UIKeyboardTypePhonePad
2589
2651
completionBlock: ^(BOOL userPressedOK, NSString *_Nullable phoneNumber) {
2590
2652
if (!userPressedOK || !phoneNumber.length ) {
2591
2653
return ;
2592
2654
}
2593
- [self showSpinner: ^{
2655
+ [self updatePhoneNumberWithString: phoneNumber completion: nil ];
2656
+ }];
2657
+ }
2658
+
2659
+ /* * @fn linkPhoneNumberWithString
2660
+ @brief Allows linking a verified phone number to the currently signed user.
2661
+ @param phoneNumber Number pass in string for automation.
2662
+ */
2663
+ - (void )linkPhoneNumberWithString : (NSString *_Nullable)phoneNumber
2664
+ completion : (void (^)(void ))completion {
2665
+ [self showSpinner: ^{
2594
2666
[[AppManager phoneAuthProvider ] verifyPhoneNumber: phoneNumber
2595
2667
UIDelegate: nil
2596
2668
completion: ^(NSString *_Nullable verificationID,
@@ -2653,13 +2725,27 @@ - (void)linkPhoneNumber {
2653
2725
return ;
2654
2726
}
2655
2727
[self logSuccess: @" link phone number succeeded." ];
2728
+ if (completion) completion ();
2656
2729
}];
2657
2730
}];
2658
2731
}];
2659
2732
}];
2660
2733
}];
2661
2734
}];
2662
2735
}];
2736
+ }
2737
+
2738
+ /* * @fn linkPhoneNumber
2739
+ @brief Allows linking a verified phone number to the currently signed user.
2740
+ */
2741
+ - (void )linkPhoneNumber {
2742
+ [self showTextInputPromptWithMessage: @" Phone #:"
2743
+ keyboardType: UIKeyboardTypePhonePad
2744
+ completionBlock: ^(BOOL userPressedOK, NSString *_Nullable phoneNumber) {
2745
+ if (!userPressedOK || !phoneNumber.length ) {
2746
+ return ;
2747
+ }
2748
+ [self linkPhoneNumberWithString: phoneNumber completion: nil ];
2663
2749
}];
2664
2750
}
2665
2751
0 commit comments