Skip to content

Commit bf545d4

Browse files
protocol86paulb777
authored andcommitted
Remove deprecated verify phone number (#1200)
* remove_deprecated_verify_phone * Fixes unit tests
1 parent 83d1004 commit bf545d4

File tree

4 files changed

+104
-91
lines changed

4 files changed

+104
-91
lines changed

Example/Auth/Sample/MainViewController.m

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -573,15 +573,10 @@
573573
*/
574574
static NSString *const kPhoneAuthSectionTitle = @"Phone Auth";
575575

576-
/** @var kPhoneNumberSignInTitle
577-
@brief The title for button to sign in with phone number.
578-
*/
579-
static NSString *const kPhoneNumberSignInTitle = @"Sign in With Phone Number";
580-
581576
/** @var kPhoneNumberSignInTitle
582577
@brief The title for button to sign in with phone number using reCAPTCHA.
583578
*/
584-
static NSString *const kPhoneNumberSignInReCaptchaTitle = @"Sign in With Phone Number (reCAPTCHA)";
579+
static NSString *const kPhoneNumberSignInReCaptchaTitle = @"Sign in With Phone Number";
585580

586581
/** @var kIsNewUserToggleTitle
587582
@brief The title for button to enable new or existing user toggle.
@@ -738,8 +733,6 @@ - (void)updateTable {
738733
[StaticContentTableViewSection sectionWithTitle:kPhoneAuthSectionTitle cells:@[
739734
[StaticContentTableViewCell cellWithTitle:kPhoneNumberSignInReCaptchaTitle
740735
action:^{ [weakSelf signInWithPhoneNumberWithPrompt]; }],
741-
[StaticContentTableViewCell cellWithTitle:kPhoneNumberSignInTitle
742-
action:^{ [weakSelf signInWithPhoneNumber]; }],
743736
[StaticContentTableViewCell cellWithTitle:kUpdatePhoneNumber
744737
action:^{ [weakSelf updatePhoneNumberWithPrompt]; }],
745738
[StaticContentTableViewCell cellWithTitle:kLinkPhoneNumber
@@ -2857,37 +2850,6 @@ - (void)createUserAuthDataResult {
28572850
}];
28582851
}
28592852

2860-
/** @fn signInWithPhoneNumber
2861-
@brief Allows sign in with phone number.
2862-
*/
2863-
- (void)signInWithPhoneNumber {
2864-
[self commonPhoneNumberInputWithTitle:@"Phone #" Completion:^(NSString *_Nullable phone) {
2865-
[self showSpinner:^{
2866-
#pragma clang diagnostic push
2867-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
2868-
[[AppManager phoneAuthProvider] verifyPhoneNumber:phone
2869-
completion:^(NSString *_Nullable verificationID,
2870-
NSError *_Nullable error) {
2871-
#pragma clang diagnostic pop
2872-
[self hideSpinner:^{
2873-
if (error) {
2874-
[self logFailure:@"failed to send verification code" error:error];
2875-
[self showMessagePrompt:error.localizedDescription];
2876-
return;
2877-
}
2878-
[self logSuccess:@"Code sent"];
2879-
2880-
[self commonPhoneNumberInputWithTitle:@"Code"
2881-
Completion:^(NSString *_Nullable verificationCode) {
2882-
[self commontPhoneVerificationWithVerificationID:verificationID
2883-
verificationCode:verificationCode];
2884-
}];
2885-
}];
2886-
}];
2887-
}];
2888-
}];
2889-
}
2890-
28912853
/** @fn signInWithPhoneNumber
28922854
@brief Allows sign in with phone number using reCAPTCHA.
28932855
@param phoneNumber Number pass in string.

Example/Auth/Tests/FIRPhoneAuthProviderTests.m

Lines changed: 103 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,16 @@ - (void)testCredentialWithVerificationID {
283283
number was provided.
284284
*/
285285
- (void)testVerifyEmptyPhoneNumber {
286+
id mockBundle = OCMClassMock([NSBundle class]);
287+
OCMStub(ClassMethod([mockBundle mainBundle])).andReturn(mockBundle);
288+
OCMStub([mockBundle objectForInfoDictionaryKey:@"CFBundleURLTypes"])
289+
.andReturn(@[ @{ @"CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
290+
OCMStub([mockBundle bundleIdentifier]).andReturn(kFakeBundleID);
291+
286292
// Empty phone number is checked on the client side so no backend RPC is mocked.
287293
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
288294
[_provider verifyPhoneNumber:@""
295+
UIDelegate:nil
289296
completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) {
290297
XCTAssertNotNil(error);
291298
XCTAssertEqual(error.code, FIRAuthErrorCodeMissingPhoneNumber);
@@ -299,6 +306,12 @@ - (void)testVerifyEmptyPhoneNumber {
299306
number was provided.
300307
*/
301308
- (void)testVerifyInvalidPhoneNumber {
309+
id mockBundle = OCMClassMock([NSBundle class]);
310+
OCMStub(ClassMethod([mockBundle mainBundle])).andReturn(mockBundle);
311+
OCMStub([mockBundle objectForInfoDictionaryKey:@"CFBundleURLTypes"])
312+
.andReturn(@[ @{ @"CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
313+
OCMStub([mockBundle bundleIdentifier]).andReturn(kFakeBundleID);
314+
302315
OCMExpect([_mockNotificationManager checkNotificationForwardingWithCallback:OCMOCK_ANY])
303316
.andCallBlock1(^(FIRAuthNotificationForwardingCallback callback) { callback(YES); });
304317
OCMStub([_mockAppCredentialManager credential])
@@ -316,6 +329,7 @@ - (void)testVerifyInvalidPhoneNumber {
316329

317330
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
318331
[_provider verifyPhoneNumber:kTestPhoneNumber
332+
UIDelegate:nil
319333
completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) {
320334
XCTAssertTrue([NSThread isMainThread]);
321335
XCTAssertNil(verificationID);
@@ -332,6 +346,12 @@ - (void)testVerifyInvalidPhoneNumber {
332346
@brief Tests a successful invocation of @c verifyPhoneNumber:completion:.
333347
*/
334348
- (void)testVerifyPhoneNumber {
349+
id mockBundle = OCMClassMock([NSBundle class]);
350+
OCMStub(ClassMethod([mockBundle mainBundle])).andReturn(mockBundle);
351+
OCMStub([mockBundle objectForInfoDictionaryKey:@"CFBundleURLTypes"])
352+
.andReturn(@[ @{ @"CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
353+
OCMStub([mockBundle bundleIdentifier]).andReturn(kFakeBundleID);
354+
335355
OCMExpect([_mockNotificationManager checkNotificationForwardingWithCallback:OCMOCK_ANY])
336356
.andCallBlock1(^(FIRAuthNotificationForwardingCallback callback) { callback(YES); });
337357
OCMStub([_mockAppCredentialManager credential])
@@ -351,6 +371,7 @@ - (void)testVerifyPhoneNumber {
351371

352372
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
353373
[_provider verifyPhoneNumber:kTestPhoneNumber
374+
UIDelegate:nil
354375
completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) {
355376
XCTAssertTrue([NSThread isMainThread]);
356377
XCTAssertNil(error);
@@ -368,6 +389,12 @@ - (void)testVerifyPhoneNumber {
368389
is disabled.
369390
*/
370391
- (void)testVerifyPhoneNumberInTestMode {
392+
id mockBundle = OCMClassMock([NSBundle class]);
393+
OCMStub(ClassMethod([mockBundle mainBundle])).andReturn(mockBundle);
394+
OCMStub([mockBundle objectForInfoDictionaryKey:@"CFBundleURLTypes"])
395+
.andReturn(@[ @{ @"CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
396+
OCMStub([mockBundle bundleIdentifier]).andReturn(kFakeBundleID);
397+
371398
// Disable app verification.
372399
FIRAuthSettings *settings = [[FIRAuthSettings alloc] init];
373400
settings.appVerificationDisabledForTesting = YES;
@@ -389,6 +416,7 @@ - (void)testVerifyPhoneNumberInTestMode {
389416

390417
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
391418
[_provider verifyPhoneNumber:kTestPhoneNumber
419+
UIDelegate:nil
392420
completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) {
393421
XCTAssertTrue([NSThread isMainThread]);
394422
XCTAssertNil(error);
@@ -406,6 +434,12 @@ - (void)testVerifyPhoneNumberInTestMode {
406434
is disabled.
407435
*/
408436
- (void)testVerifyPhoneNumberInTestModeFailure {
437+
id mockBundle = OCMClassMock([NSBundle class]);
438+
OCMStub(ClassMethod([mockBundle mainBundle])).andReturn(mockBundle);
439+
OCMStub([mockBundle objectForInfoDictionaryKey:@"CFBundleURLTypes"])
440+
.andReturn(@[ @{ @"CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
441+
OCMStub([mockBundle bundleIdentifier]).andReturn(kFakeBundleID);
442+
409443
// Disable app verification.
410444
FIRAuthSettings *settings = [[FIRAuthSettings alloc] init];
411445
settings.appVerificationDisabledForTesting = YES;
@@ -425,6 +459,7 @@ - (void)testVerifyPhoneNumberInTestModeFailure {
425459

426460
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
427461
[_provider verifyPhoneNumber:kTestPhoneNumber
462+
UIDelegate:nil
428463
completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) {
429464
XCTAssertTrue([NSThread isMainThread]);
430465
XCTAssertNil(verificationID);
@@ -901,10 +936,17 @@ - (void)testVerifyPhoneNumberUIDelegateRaiseException {
901936
@brief Tests returning an error for the app failing to forward notification.
902937
*/
903938
- (void)testNotForwardingNotification {
939+
id mockBundle = OCMClassMock([NSBundle class]);
940+
OCMStub(ClassMethod([mockBundle mainBundle])).andReturn(mockBundle);
941+
OCMStub([mockBundle objectForInfoDictionaryKey:@"CFBundleURLTypes"])
942+
.andReturn(@[ @{ @"CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
943+
OCMStub([mockBundle bundleIdentifier]).andReturn(kFakeBundleID);
944+
904945
OCMExpect([_mockNotificationManager checkNotificationForwardingWithCallback:OCMOCK_ANY])
905946
.andCallBlock1(^(FIRAuthNotificationForwardingCallback callback) { callback(NO); });
906947
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
907948
[_provider verifyPhoneNumber:kTestPhoneNumber
949+
UIDelegate:nil
908950
completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) {
909951
XCTAssertTrue([NSThread isMainThread]);
910952
XCTAssertNil(verificationID);
@@ -919,43 +961,77 @@ - (void)testNotForwardingNotification {
919961
@brief Tests returning an error for the app failing to provide an APNS device token.
920962
*/
921963
- (void)testMissingAPNSToken {
964+
id mockBundle = OCMClassMock([NSBundle class]);
965+
OCMStub(ClassMethod([mockBundle mainBundle])).andReturn(mockBundle);
966+
OCMStub([mockBundle objectForInfoDictionaryKey:@"CFBundleURLTypes"])
967+
.andReturn(@[ @{ @"CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
968+
OCMStub([mockBundle bundleIdentifier]).andReturn(kFakeBundleID);
969+
970+
// Simulate missing app token error.
922971
OCMExpect([_mockNotificationManager checkNotificationForwardingWithCallback:OCMOCK_ANY])
923972
.andCallBlock1(^(FIRAuthNotificationForwardingCallback callback) { callback(YES); });
924973
OCMExpect([_mockAppCredentialManager credential]).andReturn(nil);
925974
OCMExpect([_mockAPNSTokenManager getTokenWithCallback:OCMOCK_ANY])
926-
.andCallBlock1(^(FIRAuthAPNSTokenCallback callback) { callback(nil, nil); });
927-
// Expect verify client request to the backend wth empty token.
928-
OCMExpect([_mockBackend verifyClient:[OCMArg any] callback:[OCMArg any]])
929-
.andCallBlock2(^(FIRVerifyClientRequest *request,
930-
FIRVerifyClientResponseCallback callback) {
931-
XCTAssertNil(request.appToken);
975+
.andCallBlock1(^(FIRAuthAPNSTokenCallback callback) {
976+
NSError *error = [NSError errorWithDomain:FIRAuthErrorDomain
977+
code:FIRAuthErrorCodeMissingAppToken
978+
userInfo:nil];
979+
callback(nil, error);
980+
});
981+
OCMExpect([_mockBackend getProjectConfig:[OCMArg any] callback:[OCMArg any]])
982+
.andCallBlock2(^(FIRGetProjectConfigRequest *request,
983+
FIRGetProjectConfigResponseCallback callback) {
984+
XCTAssertNotNil(request);
985+
dispatch_async(FIRAuthGlobalWorkQueue(), ^() {
986+
id mockGetProjectConfigResponse = OCMClassMock([FIRGetProjectConfigResponse class]);
987+
OCMStub([mockGetProjectConfigResponse authorizedDomains]).
988+
andReturn(@[ kFakeAuthorizedDomain]);
989+
callback(mockGetProjectConfigResponse, nil);
990+
});
991+
});
992+
id mockUIDelegate = OCMProtocolMock(@protocol(FIRAuthUIDelegate));
993+
994+
// Expect view controller presentation by UIDelegate.
995+
OCMExpect([_mockURLPresenter presentURL:OCMOCK_ANY
996+
UIDelegate:mockUIDelegate
997+
callbackMatcher:OCMOCK_ANY
998+
completion:OCMOCK_ANY]).andDo(^(NSInvocation *invocation) {
999+
__unsafe_unretained id unretainedArgument;
1000+
// Indices 0 and 1 indicate the hidden arguments self and _cmd.
1001+
// `completion` is at index 5
1002+
[invocation getArgument:&unretainedArgument atIndex:5];
1003+
FIRAuthURLPresentationCompletion completion = unretainedArgument;
9321004
dispatch_async(FIRAuthGlobalWorkQueue(), ^() {
933-
// The backend is supposed to return an error.
934-
callback(nil, [NSError errorWithDomain:FIRAuthErrorDomain
1005+
completion(nil, [NSError errorWithDomain:FIRAuthErrorDomain
9351006
code:FIRAuthErrorCodeMissingAppToken
9361007
userInfo:nil]);
9371008
});
9381009
});
9391010

9401011
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
9411012
[_provider verifyPhoneNumber:kTestPhoneNumber
1013+
UIDelegate:mockUIDelegate
9421014
completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) {
9431015
XCTAssertTrue([NSThread isMainThread]);
944-
XCTAssertNil(verificationID);
945-
XCTAssertEqualObjects(error.domain, FIRAuthErrorDomain);
9461016
XCTAssertEqual(error.code, FIRAuthErrorCodeMissingAppToken);
1017+
XCTAssertNil(verificationID);
9471018
[expectation fulfill];
9481019
}];
9491020
[self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil];
1021+
OCMVerifyAll(_mockBackend);
9501022
OCMVerifyAll(_mockNotificationManager);
951-
OCMVerifyAll(_mockAppCredentialManager);
952-
OCMVerifyAll(_mockAPNSTokenManager);
9531023
}
9541024

9551025
/** @fn testVerifyClient
9561026
@brief Tests verifying client before sending verification code.
9571027
*/
9581028
- (void)testVerifyClient {
1029+
id mockBundle = OCMClassMock([NSBundle class]);
1030+
OCMStub(ClassMethod([mockBundle mainBundle])).andReturn(mockBundle);
1031+
OCMStub([mockBundle objectForInfoDictionaryKey:@"CFBundleURLTypes"])
1032+
.andReturn(@[ @{ @"CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
1033+
OCMStub([mockBundle bundleIdentifier]).andReturn(kFakeBundleID);
1034+
9591035
OCMExpect([_mockNotificationManager checkNotificationForwardingWithCallback:OCMOCK_ANY])
9601036
.andCallBlock1(^(FIRAuthNotificationForwardingCallback callback) { callback(YES); });
9611037
OCMExpect([_mockAppCredentialManager credential]).andReturn(nil);
@@ -1007,6 +1083,7 @@ - (void)testVerifyClient {
10071083

10081084
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
10091085
[_provider verifyPhoneNumber:kTestPhoneNumber
1086+
UIDelegate:nil
10101087
completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) {
10111088
XCTAssertTrue([NSThread isMainThread]);
10121089
XCTAssertNil(error);
@@ -1024,6 +1101,12 @@ - (void)testVerifyClient {
10241101
@brief Tests failed retry after failing to send verification code.
10251102
*/
10261103
- (void)testSendVerificationCodeFailedRetry {
1104+
id mockBundle = OCMClassMock([NSBundle class]);
1105+
OCMStub(ClassMethod([mockBundle mainBundle])).andReturn(mockBundle);
1106+
OCMStub([mockBundle objectForInfoDictionaryKey:@"CFBundleURLTypes"])
1107+
.andReturn(@[ @{ @"CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
1108+
OCMStub([mockBundle bundleIdentifier]).andReturn(kFakeBundleID);
1109+
10271110
OCMExpect([_mockNotificationManager checkNotificationForwardingWithCallback:OCMOCK_ANY])
10281111
.andCallBlock1(^(FIRAuthNotificationForwardingCallback callback) { callback(YES); });
10291112

@@ -1097,6 +1180,7 @@ - (void)testSendVerificationCodeFailedRetry {
10971180

10981181
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
10991182
[_provider verifyPhoneNumber:kTestPhoneNumber
1183+
UIDelegate:nil
11001184
completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) {
11011185
XCTAssertTrue([NSThread isMainThread]);
11021186
XCTAssertNil(verificationID);
@@ -1114,6 +1198,12 @@ - (void)testSendVerificationCodeFailedRetry {
11141198
@brief Tests successful retry after failing to send verification code.
11151199
*/
11161200
- (void)testSendVerificationCodeSuccessFulRetry {
1201+
id mockBundle = OCMClassMock([NSBundle class]);
1202+
OCMStub(ClassMethod([mockBundle mainBundle])).andReturn(mockBundle);
1203+
OCMStub([mockBundle objectForInfoDictionaryKey:@"CFBundleURLTypes"])
1204+
.andReturn(@[ @{ @"CFBundleURLSchemes" : @[ kFakeReverseClientID ] } ]);
1205+
OCMStub([mockBundle bundleIdentifier]).andReturn(kFakeBundleID);
1206+
11171207
OCMExpect([_mockNotificationManager checkNotificationForwardingWithCallback:OCMOCK_ANY])
11181208
.andCallBlock1(^(FIRAuthNotificationForwardingCallback callback) { callback(YES); });
11191209

@@ -1189,6 +1279,7 @@ - (void)testSendVerificationCodeSuccessFulRetry {
11891279

11901280
XCTestExpectation *expectation = [self expectationWithDescription:@"callback"];
11911281
[_provider verifyPhoneNumber:kTestPhoneNumber
1282+
UIDelegate:nil
11921283
completion:^(NSString *_Nullable verificationID, NSError *_Nullable error) {
11931284
XCTAssertNil(error);
11941285
XCTAssertEqualObjects(verificationID, kTestVerificationID);

Firebase/Auth/Source/AuthProviders/Phone/FIRPhoneAuthProvider.m

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,6 @@ - (nullable instancetype)initWithAuth:(FIRAuth *)auth {
108108
return self;
109109
}
110110

111-
- (void)verifyPhoneNumber:(NSString *)phoneNumber
112-
completion:(nullable FIRVerificationResultCallback)completion {
113-
dispatch_async(FIRAuthGlobalWorkQueue(), ^{
114-
[self internalVerifyPhoneNumber:phoneNumber completion:^(NSString *_Nullable verificationID,
115-
NSError *_Nullable error) {
116-
if (completion) {
117-
dispatch_async(dispatch_get_main_queue(), ^{
118-
completion(verificationID, error);
119-
});
120-
}
121-
}];
122-
});
123-
}
124-
125111
- (void)verifyPhoneNumber:(NSString *)phoneNumber
126112
UIDelegate:(nullable id<FIRAuthUIDelegate>)UIDelegate
127113
completion:(nullable FIRVerificationResultCallback)completion {

Firebase/Auth/Source/Public/FIRPhoneAuthProvider.h

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -61,32 +61,6 @@ NS_SWIFT_NAME(PhoneAuthProvider)
6161
*/
6262
+ (instancetype)providerWithAuth:(FIRAuth *)auth NS_SWIFT_NAME(provider(auth:));
6363

64-
/** @fn verifyPhoneNumber:completion:
65-
@brief Please use `verifyPhoneNumber:UIDelegate:completion:` instead.
66-
67-
@param phoneNumber The phone number to be verified.
68-
@param completion The callback to be invoked when the verification flow is finished.
69-
70-
@remarks Possible error codes:
71-
72-
+ `FIRAuthErrorCodeAppNotVerified` - Indicates that Firebase could not retrieve the
73-
silent push notification and therefore could not verify your app.
74-
+ `FIRAuthErrorCodeInvalidAppCredential` - Indicates that The APNs device token provided
75-
is either incorrect or does not match the private certificate uploaded to the Firebase
76-
Console.
77-
+ `FIRAuthErrorCodeQuotaExceeded` - Indicates that the phone verification quota for this
78-
project has been exceeded.
79-
+ `FIRAuthErrorCodeInvalidPhoneNumber` - Indicates that the phone number provided is
80-
invalid.
81-
+ `FIRAuthErrorCodeMissingPhoneNumber` - Indicates that a phone number was not provided.
82-
+ `FIRAuthErrorCodeMissingAppToken` - Indicates that the APNs device token could not be
83-
obtained. The app may not have set up remote notification correctly, or may fail to
84-
forward the APNs device token to FIRAuth if app delegate swizzling is disabled.
85-
*/
86-
- (void)verifyPhoneNumber:(NSString *)phoneNumber
87-
completion:(nullable FIRVerificationResultCallback)completion
88-
__attribute__((deprecated));
89-
9064
/** @fn verifyPhoneNumber:UIDelegate:completion:
9165
@brief Starts the phone number authentication flow by sending a verifcation code to the
9266
specified phone number.

0 commit comments

Comments
 (0)