|
39 | 39 | #import "UserInfoViewController.h"
|
40 | 40 | #import "UserTableViewCell.h"
|
41 | 41 |
|
| 42 | +#import "FIRAuth_Internal.h" |
| 43 | +#import "FIRAuthAPNSToken.h" |
| 44 | +#import "FIRAuthAPNSTokenManager.h" |
| 45 | +#import "FIRAuthAppCredential.h" |
| 46 | +#import "FIRAuthAppCredentialManager.h" |
| 47 | +#import "FIRAuthBackend.h" |
| 48 | +#import "FIRVerifyClientRequest.h" |
| 49 | +#import "FIRVerifyClientResponse.h" |
| 50 | +#import "FIRSendVerificationCodeRequest.h" |
| 51 | + |
42 | 52 | NS_ASSUME_NONNULL_BEGIN
|
43 | 53 |
|
44 | 54 | /** @typedef textInputCompletionBlock
|
|
578 | 588 | */
|
579 | 589 | static NSString *const kPhoneNumberSignInReCaptchaTitle = @"Sign in With Phone Number";
|
580 | 590 |
|
| 591 | +/** @var kVerifyIOSClientTitle |
| 592 | + @brief The title for button to verify iOS client. |
| 593 | + */ |
| 594 | +static NSString *const kVerifyIOSClientTitle = @"Verify iOS client"; |
| 595 | + |
581 | 596 | /** @var kIsNewUserToggleTitle
|
582 | 597 | @brief The title for button to enable new or existing user toggle.
|
583 | 598 | */
|
@@ -741,6 +756,8 @@ - (void)updateTable {
|
741 | 756 | action:^{
|
742 | 757 | [weakSelf unlinkFromProvider:FIRPhoneAuthProviderID completion:nil];
|
743 | 758 | }],
|
| 759 | + [StaticContentTableViewCell cellWithTitle:kVerifyIOSClientTitle |
| 760 | + action:^{ [weakSelf verifyIOSClient]; }], |
744 | 761 | ]],
|
745 | 762 | [StaticContentTableViewSection sectionWithTitle:kSectionTitleSignIn cells:@[
|
746 | 763 | [StaticContentTableViewCell cellWithTitle:kSwitchToInMemoryUserTitle
|
@@ -1605,17 +1622,19 @@ - (void)removeIDTokenListener {
|
1605 | 1622 | @param string The string to add to the console.
|
1606 | 1623 | */
|
1607 | 1624 | - (void)log:(NSString *)string {
|
1608 |
| - NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; |
1609 |
| - dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; |
1610 |
| - NSString *date = [dateFormatter stringFromDate:[NSDate date]]; |
1611 |
| - if (!_consoleString) { |
1612 |
| - _consoleString = [NSMutableString string]; |
1613 |
| - } |
1614 |
| - [_consoleString appendString:[NSString stringWithFormat:@"%@ %@\n", date, string]]; |
1615 |
| - _consoleTextView.text = _consoleString; |
| 1625 | + dispatch_async(dispatch_get_main_queue(), ^{ |
| 1626 | + NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; |
| 1627 | + dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss"; |
| 1628 | + NSString *date = [dateFormatter stringFromDate:[NSDate date]]; |
| 1629 | + if (!_consoleString) { |
| 1630 | + _consoleString = [NSMutableString string]; |
| 1631 | + } |
| 1632 | + [_consoleString appendString:[NSString stringWithFormat:@"%@ %@\n", date, string]]; |
| 1633 | + _consoleTextView.text = _consoleString; |
1616 | 1634 |
|
1617 |
| - CGRect targetRect = CGRectMake(0, _consoleTextView.contentSize.height - 1, 1, 1); |
1618 |
| - [_consoleTextView scrollRectToVisible:targetRect animated:YES]; |
| 1635 | + CGRect targetRect = CGRectMake(0, _consoleTextView.contentSize.height - 1, 1, 1); |
| 1636 | + [_consoleTextView scrollRectToVisible:targetRect animated:YES]; |
| 1637 | + }); |
1619 | 1638 | }
|
1620 | 1639 |
|
1621 | 1640 | /** @fn logSuccess:
|
@@ -2885,6 +2904,59 @@ - (void)signInWithPhoneNumber:(NSString *_Nullable)phoneNumber
|
2885 | 2904 | }];
|
2886 | 2905 | }
|
2887 | 2906 |
|
| 2907 | +/** @fn verifyIOSClient |
| 2908 | + @brief Trigger verify iOS client by sending a verification code to the test number. |
| 2909 | + */ |
| 2910 | +- (void)verifyIOSClient { |
| 2911 | + [[AppManager auth].tokenManager getTokenWithCallback:^(FIRAuthAPNSToken *_Nullable token, |
| 2912 | + NSError *_Nullable error) { |
| 2913 | + if (!token) { |
| 2914 | + [self logFailure:@"Verify iOS client failed." error:error]; |
| 2915 | + return; |
| 2916 | + } |
| 2917 | + FIRVerifyClientRequest *request = |
| 2918 | + [[FIRVerifyClientRequest alloc] initWithAppToken:token.string |
| 2919 | + isSandbox:token.type == FIRAuthAPNSTokenTypeSandbox |
| 2920 | + requestConfiguration:[AppManager auth].requestConfiguration]; |
| 2921 | + [FIRAuthBackend verifyClient:request callback:^(FIRVerifyClientResponse *_Nullable response, |
| 2922 | + NSError *_Nullable error) { |
| 2923 | + if (error) { |
| 2924 | + [self logFailure:@"Verify iOS client failed." error:error]; |
| 2925 | + return; |
| 2926 | + } |
| 2927 | + NSTimeInterval timeout = [response.suggestedTimeOutDate timeIntervalSinceNow]; |
| 2928 | + [[AppManager auth].appCredentialManager |
| 2929 | + didStartVerificationWithReceipt:response.receipt |
| 2930 | + timeout:timeout |
| 2931 | + callback:^(FIRAuthAppCredential *credential) { |
| 2932 | + if (!credential.secret) { |
| 2933 | + [self logFailure:@"Failed to receive remote notification to verify app identity." |
| 2934 | + error:error]; |
| 2935 | + return; |
| 2936 | + } |
| 2937 | + NSString *testPhoneNumber = @"+16509964692"; |
| 2938 | + FIRSendVerificationCodeRequest *request = |
| 2939 | + [[FIRSendVerificationCodeRequest alloc] initWithPhoneNumber:testPhoneNumber |
| 2940 | + appCredential:credential |
| 2941 | + reCAPTCHAToken:nil |
| 2942 | + requestConfiguration: |
| 2943 | + [AppManager auth].requestConfiguration]; |
| 2944 | + [FIRAuthBackend sendVerificationCode:request |
| 2945 | + callback:^(FIRSendVerificationCodeResponse *_Nullable response, |
| 2946 | + NSError *_Nullable error) { |
| 2947 | + if (error) { |
| 2948 | + [self logFailure:@"Verify iOS client failed." error:error]; |
| 2949 | + return; |
| 2950 | + } else { |
| 2951 | + [self logSuccess:@"Verify iOS client succeeded."]; |
| 2952 | + [self showMessagePrompt:@"Verify iOS client succeed."]; |
| 2953 | + } |
| 2954 | + }]; |
| 2955 | + }]; |
| 2956 | + }]; |
| 2957 | + }]; |
| 2958 | +} |
| 2959 | + |
2888 | 2960 | /** @fn signInWithPhoneNumberWithPrompt
|
2889 | 2961 | @brief Allows sign in with phone number via popup prompt.
|
2890 | 2962 | */
|
|
0 commit comments