From 14764b8d60a6ad023d8fa5b7f81d42378d92e6fe Mon Sep 17 00:00:00 2001 From: Rosalyn Tan Date: Wed, 30 Sep 2020 15:51:09 -0700 Subject: [PATCH] Remove deprecated auth APIs (#6607) * Remove deprecated APIs from public header. * Remove deprecated API implementations. * Also remove deprecated APIs from FIRUser. * Update unit tests. * Update sample app. * Update changelog. --- FirebaseAuth/CHANGELOG.md | 3 + FirebaseAuth/Sources/Auth/FIRAuth.m | 36 ----------- .../Sources/Public/FirebaseAuth/FIRAuth.h | 40 ------------ .../Sources/Public/FirebaseAuth/FIRUser.h | 23 ------- FirebaseAuth/Sources/User/FIRUser.m | 16 ----- .../Sample/Sample/MainViewController+User.m | 29 --------- FirebaseAuth/Tests/Unit/FIRAuthTests.m | 63 +------------------ FirebaseAuth/Tests/Unit/FIRUserTests.m | 28 ++++----- 8 files changed, 20 insertions(+), 218 deletions(-) diff --git a/FirebaseAuth/CHANGELOG.md b/FirebaseAuth/CHANGELOG.md index bb3be2bedf2..435d69215e4 100644 --- a/FirebaseAuth/CHANGELOG.md +++ b/FirebaseAuth/CHANGELOG.md @@ -1,3 +1,6 @@ +# Unreleased +- [removed] Remove deprecated APIs `dataForKey`,`fetchProvidersForEmail:completion`, `signInAndRetrieveDataWithCredential:completion`, `reauthenticateAndRetrieveDataWithCredential:completion`, `linkAndRetrieveDataWithCredential:completion`. (#6607) + # v6.9.1 - [fixed] Internal source documentation. (#6371) diff --git a/FirebaseAuth/Sources/Auth/FIRAuth.m b/FirebaseAuth/Sources/Auth/FIRAuth.m index 5edb1ef9902..dc307d3fb4d 100644 --- a/FirebaseAuth/Sources/Auth/FIRAuth.m +++ b/FirebaseAuth/Sources/Auth/FIRAuth.m @@ -204,15 +204,6 @@ @interface FIRActionCodeInfo () @implementation FIRActionCodeInfo -- (NSString *)dataForKey:(FIRActionDataKey)key { - switch (key) { - case FIRActionCodeEmailKey: - return self.email; - case FIRActionCodeFromEmailKey: - return self.previousEmail; - } -} - - (instancetype)initWithOperation:(FIRActionCodeOperation)operation email:(NSString *)email newEmail:(nullable NSString *)newEmail { @@ -589,25 +580,6 @@ - (nullable FIRUser *)currentUser { return result; } -- (void)fetchProvidersForEmail:(NSString *)email - completion:(nullable FIRProviderQueryCallback)completion { - dispatch_async(FIRAuthGlobalWorkQueue(), ^{ - FIRCreateAuthURIRequest *request = - [[FIRCreateAuthURIRequest alloc] initWithIdentifier:email - continueURI:@"http://www.google.com/" - requestConfiguration:self->_requestConfiguration]; - [FIRAuthBackend - createAuthURI:request - callback:^(FIRCreateAuthURIResponse *_Nullable response, NSError *_Nullable error) { - if (completion) { - dispatch_async(dispatch_get_main_queue(), ^{ - completion(response.allProviders, error); - }); - } - }]; - }); -} - - (void)signInWithProvider:(id)provider UIDelegate:(nullable id)UIDelegate completion:(nullable FIRAuthDataResultCallback)completion { @@ -858,16 +830,8 @@ - (void)internalSignInAndRetrieveDataWithEmail:(nonnull NSString *)email }]; } -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - (void)signInWithCredential:(FIRAuthCredential *)credential completion:(nullable FIRAuthDataResultCallback)completion { - [self signInAndRetrieveDataWithCredential:credential completion:completion]; -} -#pragma clang diagnostic pop - -- (void)signInAndRetrieveDataWithCredential:(FIRAuthCredential *)credential - completion:(nullable FIRAuthDataResultCallback)completion { dispatch_async(FIRAuthGlobalWorkQueue(), ^{ FIRAuthDataResultCallback callback = [self signInFlowAuthDataResultCallbackByDecoratingCallback:completion]; diff --git a/FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuth.h b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuth.h index eeda72c452d..fef7a4bbcbd 100644 --- a/FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuth.h +++ b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRAuth.h @@ -176,19 +176,6 @@ typedef void (^FIRApplyActionCodeCallback)(NSError *_Nullable error) typedef void (^FIRAuthVoidErrorCallback)(NSError *_Nullable) NS_SWIFT_NAME(AuthVoidErrorCallback); -/** - @brief Deprecated. Please directly use email or previousEmail properties instead. - */ -typedef NS_ENUM(NSInteger, FIRActionDataKey) { - /** Deprecated. Please directly use email property instead. */ - FIRActionCodeEmailKey = 0, - - /** Deprecated. Please directly use previousEmail property instead. */ - FIRActionCodeFromEmailKey = 1, - -} NS_SWIFT_NAME(ActionDataKey) - DEPRECATED_MSG_ATTRIBUTE("Please directly use email or previousEmail properties instead."); - /** @class FIRActionCodeInfo @brief Manages information regarding action codes. */ @@ -227,12 +214,6 @@ typedef NS_ENUM(NSInteger, FIRActionCodeOperation) { */ @property(nonatomic, readonly) FIRActionCodeOperation operation; -/** @fn dataForKey: - @brief Deprecated. Please directly use email or previousEmail properties instead. - */ -- (NSString *)dataForKey:(FIRActionDataKey)key - DEPRECATED_MSG_ATTRIBUTE("Please directly use email or previousEmail properties instead."); - /** @property email @brief The email address to which the code was sent. The new email address in the case of FIRActionCodeOperationRecoverEmail. @@ -388,16 +369,6 @@ NS_SWIFT_NAME(Auth) - (void)updateCurrentUser:(FIRUser *)user completion:(nullable void (^)(NSError *_Nullable error))completion; -/** @fn fetchProvidersForEmail:completion: - @brief Please use fetchSignInMethodsForEmail:completion: for Objective-C or - fetchSignInMethods(forEmail:completion:) for Swift instead. - */ -- (void)fetchProvidersForEmail:(NSString *)email - completion:(nullable void (^)(NSArray *_Nullable providers, - NSError *_Nullable error))completion - DEPRECATED_MSG_ATTRIBUTE("Please use fetchSignInMethodsForEmail:completion: for Objective-C or " - "fetchSignInMethods(forEmail:completion:) for Swift instead."); - /** @fn fetchSignInMethodsForEmail:completion: @brief Fetches the list of all sign-in methods previously used for the provided email address. @@ -519,17 +490,6 @@ NS_SWIFT_NAME(Auth) NSError *_Nullable error))completion API_UNAVAILABLE(watchos); -/** @fn signInAndRetrieveDataWithCredential:completion: - @brief Please use signInWithCredential:completion: for Objective-C or " - "signIn(with:completion:) for Swift instead. - */ -- (void)signInAndRetrieveDataWithCredential:(FIRAuthCredential *)credential - completion: - (nullable void (^)(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error))completion - DEPRECATED_MSG_ATTRIBUTE("Please use signInWithCredential:completion: for Objective-C or " - "signIn(with:completion:) for Swift instead."); - /** @fn signInWithCredential:completion: @brief Asynchronously signs in to Firebase with the given 3rd-party credentials (e.g. a Facebook login Access Token, a Google ID Token/Access Token pair, etc.) and returns additional diff --git a/FirebaseAuth/Sources/Public/FirebaseAuth/FIRUser.h b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRUser.h index 7cfefc142a2..6390ec55718 100644 --- a/FirebaseAuth/Sources/Public/FirebaseAuth/FIRUser.h +++ b/FirebaseAuth/Sources/Public/FirebaseAuth/FIRUser.h @@ -275,18 +275,6 @@ NS_SWIFT_NAME(User) completion:(nullable void (^)(FIRAuthDataResult *_Nullable authResult, NSError *_Nullable error))completion; -/** @fn reauthenticateAndRetrieveDataWithCredential:completion: - @brief Please use linkWithCredential:completion: for Objective-C - or link(withCredential:completion:) for Swift instead. - */ -- (void)reauthenticateAndRetrieveDataWithCredential:(FIRAuthCredential *)credential - completion:(nullable void (^)( - FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error))completion - DEPRECATED_MSG_ATTRIBUTE("Please use reauthenticateWithCredential:completion: for" - " Objective-C or reauthenticate(withCredential:completion:)" - " for Swift instead."); - /** @fn reauthenticateWithProvider:UIDelegate:completion: @brief Renews the user's authentication using the provided auth provider instance. @@ -362,17 +350,6 @@ NS_SWIFT_NAME(User) completion:(nullable void (^)(NSString *_Nullable token, NSError *_Nullable error))completion; -/** @fn linkAndRetrieveDataWithCredential:completion: - @brief Please use linkWithCredential:completion: for Objective-C - or link(withCredential:completion:) for Swift instead. - */ -- (void)linkAndRetrieveDataWithCredential:(FIRAuthCredential *)credential - completion: - (nullable void (^)(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error))completion - DEPRECATED_MSG_ATTRIBUTE("Please use linkWithCredential:completion: for Objective-C " - "or link(withCredential:completion:) for Swift instead."); - /** @fn linkWithCredential:completion: @brief Associates a user account from a third-party identity provider with this user and returns additional identity provider data. diff --git a/FirebaseAuth/Sources/User/FIRUser.m b/FirebaseAuth/Sources/User/FIRUser.m index f0b4a0cc94d..68d8900c351 100644 --- a/FirebaseAuth/Sources/User/FIRUser.m +++ b/FirebaseAuth/Sources/User/FIRUser.m @@ -787,16 +787,8 @@ - (void)reloadWithCompletion:(nullable FIRUserProfileChangeCallback)completion { #pragma mark - -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - (void)reauthenticateWithCredential:(FIRAuthCredential *)credential completion:(nullable FIRAuthDataResultCallback)completion { - [self reauthenticateAndRetrieveDataWithCredential:credential completion:completion]; -} -#pragma clang diagnostic pop - -- (void)reauthenticateAndRetrieveDataWithCredential:(FIRAuthCredential *)credential - completion:(nullable FIRAuthDataResultCallback)completion { dispatch_async(FIRAuthGlobalWorkQueue(), ^{ [self->_auth internalSignInAndRetrieveDataWithCredential:credential @@ -1056,16 +1048,8 @@ - (void)internalVerifyBeforeUpdateEmailWithNewEmail:(NSString *)newEmail }); } -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - (void)linkWithCredential:(FIRAuthCredential *)credential completion:(nullable FIRAuthDataResultCallback)completion { - [self linkAndRetrieveDataWithCredential:credential completion:completion]; -} -#pragma clang diagnostic pop - -- (void)linkAndRetrieveDataWithCredential:(FIRAuthCredential *)credential - completion:(nullable FIRAuthDataResultCallback)completion { dispatch_async(FIRAuthGlobalWorkQueue(), ^{ if (self->_providerData[credential.provider]) { callInMainThreadWithAuthDataResultAndError(completion, nil, diff --git a/FirebaseAuth/Tests/Sample/Sample/MainViewController+User.m b/FirebaseAuth/Tests/Sample/Sample/MainViewController+User.m index 41164b13fb0..7d6362a54fa 100644 --- a/FirebaseAuth/Tests/Sample/Sample/MainViewController+User.m +++ b/FirebaseAuth/Tests/Sample/Sample/MainViewController+User.m @@ -35,8 +35,6 @@ - (StaticContentTableViewSection *)userSection { action:^{ [weakSelf updatePassword]; }], [StaticContentTableViewCell cellWithTitle:@"Update Phone Number" action:^{ [weakSelf updatePhoneNumber]; }], - [StaticContentTableViewCell cellWithTitle:@"Get Provider IDs for Email" - action:^{ [weakSelf getProvidersForEmail]; }], [StaticContentTableViewCell cellWithTitle:@"Get Sign-in methods for Email" action:^{ [weakSelf getAllSignInMethodsForEmail]; }], [StaticContentTableViewCell cellWithTitle:@"Reload User" @@ -112,33 +110,6 @@ - (void)reloadUser { }]; } -- (void)getProvidersForEmail { - [self showTextInputPromptWithMessage:@"Email:" - completionBlock:^(BOOL userPressedOK, NSString *_Nullable userInput) { - if (!userPressedOK || !userInput.length) { - return; - } - [self showSpinner:^{ - [[AppManager auth] fetchProvidersForEmail:userInput - completion:^(NSArray *_Nullable providers, - NSError *_Nullable error) { - if (error) { - [self logFailure:@"get providers for email failed" error:error]; - } else { - [self logSuccess:@"get providers for email succeeded."]; - } - [self hideSpinner:^{ - if (error) { - [self showMessagePrompt:error.localizedDescription]; - return; - } - [self showMessagePrompt:[providers componentsJoinedByString:@", "]]; - }]; - }]; - }]; - }]; -} - - (void)getAllSignInMethodsForEmail { [self showTextInputPromptWithMessage:@"Email:" completionBlock:^(BOOL userPressedOK, NSString *_Nullable userInput) { diff --git a/FirebaseAuth/Tests/Unit/FIRAuthTests.m b/FirebaseAuth/Tests/Unit/FIRAuthTests.m index afff0151f93..84ad4134686 100644 --- a/FirebaseAuth/Tests/Unit/FIRAuthTests.m +++ b/FirebaseAuth/Tests/Unit/FIRAuthTests.m @@ -378,39 +378,6 @@ - (void)tearDown { #pragma mark - Server API Tests -/** @fn testFetchProvidersForEmailSuccess - @brief Tests the flow of a successful @c fetchProvidersForEmail:completion: call. - */ -- (void)testFetchProvidersForEmailSuccess { - NSArray *allProviders = @[ FIRGoogleAuthProviderID, FIREmailAuthProviderID ]; - OCMExpect([_mockBackend createAuthURI:[OCMArg any] callback:[OCMArg any]]) - .andCallBlock2( - ^(FIRCreateAuthURIRequest *_Nullable request, FIRCreateAuthURIResponseCallback callback) { - XCTAssertEqualObjects(request.identifier, kEmail); - XCTAssertNotNil(request.endpoint); - XCTAssertEqualObjects(request.APIKey, kAPIKey); - dispatch_async(FIRAuthGlobalWorkQueue(), ^() { - id mockCreateAuthURIResponse = OCMClassMock([FIRCreateAuthURIResponse class]); - OCMStub([mockCreateAuthURIResponse allProviders]).andReturn(allProviders); - callback(mockCreateAuthURIResponse, nil); - }); - }); - XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - [[FIRAuth auth] - fetchProvidersForEmail:kEmail - completion:^(NSArray *_Nullable providers, NSError *_Nullable error) { -#pragma clang diagnostic pop - XCTAssertTrue([NSThread isMainThread]); - XCTAssertEqualObjects(providers, allProviders); - XCTAssertNil(error); - [expectation fulfill]; - }]; - [self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil]; - OCMVerifyAll(_mockBackend); -} - /** @fn testFetchSignInMethodsForEmailSuccess @brief Tests the flow of a successful @c fetchSignInMethodsForEmail:completion: call. */ @@ -443,30 +410,6 @@ - (void)testFetchSignInMethodsForEmailSuccess { OCMVerifyAll(_mockBackend); } -/** @fn testFetchProvidersForEmailFailure - @brief Tests the flow of a failed @c fetchProvidersForEmail:completion: call. - */ -- (void)testFetchProvidersForEmailFailure { - OCMExpect([_mockBackend createAuthURI:[OCMArg any] callback:[OCMArg any]]) - .andDispatchError2([FIRAuthErrorUtils tooManyRequestsErrorWithMessage:nil]); - XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - [[FIRAuth auth] - fetchProvidersForEmail:kEmail - completion:^(NSArray *_Nullable providers, NSError *_Nullable error) { - -#pragma clang pop - XCTAssertTrue([NSThread isMainThread]); - XCTAssertNil(providers); - XCTAssertEqual(error.code, FIRAuthErrorCodeTooManyRequests); - XCTAssertNotNil(error.userInfo[NSLocalizedDescriptionKey]); - [expectation fulfill]; - }]; - [self waitForExpectationsWithTimeout:kExpectationTimeout handler:nil]; - OCMVerifyAll(_mockBackend); -} - /** @fn testFetchSignInMethodsForEmailFailure @brief Tests the flow of a failed @c fetchSignInMethodsForEmail:completion: call. */ @@ -1363,11 +1306,11 @@ - (void)testSignInWithOAuthCredentialSuccess { } #endif // TARGET_OS_IOS -/** @fn testSignInAndRetrieveDataWithCredentialSuccess - @brief Tests the flow of a successful @c signInAndRetrieveDataWithCredential:completion: call +/** @fn testSignInWithCredentialSuccess + @brief Tests the flow of a successful @c signInWithCredential:completion: call with an Google Sign-In credential. */ -- (void)testSignInAndRetrieveDataWithCredentialSuccess { +- (void)testSignInWithCredentialSuccess { OCMExpect([_mockBackend verifyAssertion:[OCMArg any] callback:[OCMArg any]]) .andCallBlock2(^(FIRVerifyAssertionRequest *_Nullable request, FIRVerifyAssertionResponseCallback callback) { diff --git a/FirebaseAuth/Tests/Unit/FIRUserTests.m b/FirebaseAuth/Tests/Unit/FIRUserTests.m index 5d19a193fcd..d4ffa1cd0f2 100644 --- a/FirebaseAuth/Tests/Unit/FIRUserTests.m +++ b/FirebaseAuth/Tests/Unit/FIRUserTests.m @@ -1637,11 +1637,11 @@ - (void)testReauthenticateSuccess { OCMVerifyAll(_mockBackend); } -/** @fn testReauthenticateAndRetrieveDataSuccess - @brief Tests the flow of a successful @c reauthenticateAndRetrieveDataWithCredential:completion: +/** @fn testReauthenticateWithCredentialSuccess + @brief Tests the flow of a successful @c reauthenticateWithCredential:completion: call. */ -- (void)testReauthenticateAndRetrieveDataSuccess { +- (void)testReauthenticateWithCredentialSuccess { [self expectVerifyAssertionRequest:FIRGoogleAuthProviderID federatedID:kGoogleID displayName:kGoogleDisplayName @@ -1864,7 +1864,7 @@ - (void)testReauthenticateUserMismatchFailure { } /** @fn testlinkAndRetrieveDataSuccess - @brief Tests the flow of a successful @c linkAndRetrieveDataWithCredential:completion: + @brief Tests the flow of a successful @c linkWithCredential:completion: call. */ - (void)testlinkAndRetrieveDataSuccess { @@ -1932,7 +1932,7 @@ - (void)testlinkAndRetrieveDataSuccess { } /** @fn testlinkAndRetrieveDataError - @brief Tests the flow of an unsuccessful @c linkAndRetrieveDataWithCredential:completion: + @brief Tests the flow of an unsuccessful @c linkWithCredential:completion: call with an error from the backend. */ - (void)testlinkAndRetrieveDataError { @@ -1992,7 +1992,7 @@ - (void)testlinkAndRetrieveDataError { } /** @fn testlinkAndRetrieveDataProviderAlreadyLinked - @brief Tests the flow of an unsuccessful @c linkAndRetrieveDataWithCredential:completion: + @brief Tests the flow of an unsuccessful @c linkWithCredential:completion: call with FIRAuthErrorCodeProviderAlreadyLinked, which is a client side error. */ - (void)testlinkAndRetrieveDataProviderAlreadyLinked { @@ -2036,7 +2036,7 @@ - (void)testlinkAndRetrieveDataProviderAlreadyLinked { } /** @fn testlinkAndRetrieveDataErrorAutoSignOut - @brief Tests the flow of an unsuccessful @c linkAndRetrieveDataWithCredential:completion: + @brief Tests the flow of an unsuccessful @c linkWithCredential:completion: call that automatically signs out. */ - (void)testlinkAndRetrieveDataErrorAutoSignOut { @@ -2089,7 +2089,7 @@ - (void)testlinkAndRetrieveDataErrorAutoSignOut { } /** @fn testlinkEmailAndRetrieveDataSuccess - @brief Tests the flow of a successful @c linkAndRetrieveDataWithCredential:completion: + @brief Tests the flow of a successful @c linkWithCredential:completion: invocation for email credential. */ - (void)testlinkEmailAndRetrieveDataSuccess { @@ -2163,7 +2163,7 @@ - (void)testlinkEmailAndRetrieveDataSuccess { } /** @fn testlinkEmailProviderAlreadyLinkedError - @brief Tests the flow of an unsuccessful @c linkAndRetrieveDataWithCredential:completion: + @brief Tests the flow of an unsuccessful @c linkWithCredential:completion: invocation for email credential and FIRAuthErrorCodeProviderAlreadyLinked which is a client side error. */ @@ -2250,7 +2250,7 @@ - (void)testlinkEmailProviderAlreadyLinkedError { } /** @fn testlinkEmailAndRetrieveDataError - @brief Tests the flow of an unsuccessful @c linkAndRetrieveDataWithCredential:completion: + @brief Tests the flow of an unsuccessful @c linkWithCredential:completion: invocation for email credential and an error from the backend. */ - (void)testlinkEmailAndRetrieveDataError { @@ -2305,7 +2305,7 @@ - (void)testlinkEmailAndRetrieveDataError { } /** @fn testlinkEmailAndRetrieveDataError - @brief Tests the flow of an unsuccessful @c linkAndRetrieveDataWithCredential:completion: + @brief Tests the flow of an unsuccessful @c linkWithCredential:completion: invocation that automatically signs out. */ - (void)testlinkEmailAndRetrieveDataErrorAutoSignOut { @@ -2510,7 +2510,7 @@ - (void)testlinkCredentialProviderAlreadyLinkedError { #if TARGET_OS_IOS /** @fn testlinkPhoneAuthCredentialSuccess - @brief Tests the flow of a successful @c linkAndRetrieveDataWithCredential:completion: + @brief Tests the flow of a successful @c linkWithCredential:completion: call using a phoneAuthCredential. */ - (void)testlinkPhoneAuthCredentialSuccess { @@ -2668,7 +2668,7 @@ - (void)testUnlinkPhoneAuthCredentialSuccess { } /** @fn testlinkPhoneAuthCredentialFailure - @brief Tests the flow of a failed call to @c linkAndRetrieveDataWithCredential:completion: due + @brief Tests the flow of a failed call to @c linkWithCredential:completion: due to a phone provider already being linked. */ - (void)testlinkPhoneAuthCredentialFailure { @@ -2716,7 +2716,7 @@ - (void)testlinkPhoneAuthCredentialFailure { } /** @fn testlinkPhoneCredentialAlreadyExistsError - @brief Tests the flow of @c linkAndRetrieveDataWithCredential:completion: + @brief Tests the flow of @c linkWithCredential:completion: call using a phoneAuthCredential and a credential already exisits error. In this case we should get a FIRAuthCredential in the error object. */