From 4c0562ecbdfba94e134f4b0e2c57e01979c5823a Mon Sep 17 00:00:00 2001 From: Chuan Ren Date: Thu, 4 Apr 2019 11:54:31 -0700 Subject: [PATCH 1/4] Clean deprecated apis --- Example/Auth/Sample/MainViewController.m | 95 +++++----- Firebase/Auth/Source/Auth/FIRAuth.m | 114 +----------- Firebase/Auth/Source/Public/FIRAuth.h | 175 ++++-------------- Firebase/Auth/Source/Public/FIRAuthErrors.h | 14 -- .../Auth/Source/Public/FIREmailAuthProvider.h | 14 +- .../Auth/Source/Public/FIROAuthProvider.h | 12 -- Firebase/Auth/Source/Public/FIRUser.h | 55 +++--- Firebase/Auth/Source/User/FIRUser.m | 24 +-- 8 files changed, 123 insertions(+), 380 deletions(-) diff --git a/Example/Auth/Sample/MainViewController.m b/Example/Auth/Sample/MainViewController.m index 6d74531b1b2..a4c17c09923 100644 --- a/Example/Auth/Sample/MainViewController.m +++ b/Example/Auth/Sample/MainViewController.m @@ -1131,8 +1131,9 @@ - (void)signInWithProvider:(nonnull id)provider callback:(void(^)( [self logFailedTest:@"The test needs a valid credential to continue."]; return; } - [[AppManager auth] signInWithCredential:credential completion:^(FIRUser *_Nullable user, - NSError *_Nullable error) { + [[AppManager auth] signInAndRetrieveDataWithCredential:credential + completion:^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { if (error) { [self logFailure:@"sign-in with provider failed" error:error]; [self logFailedTest:@"Sign-in should succeed"]; @@ -1283,9 +1284,9 @@ - (void)automatedEmailSignUp { [auth signOut:NULL]; FIRAuthCredential *credential = [FIREmailAuthProvider credentialWithEmail:kFakeEmail password:kFakePassword]; - [auth signInWithCredential:credential - completion:^(FIRUser *_Nullable user, - NSError *_Nullable error) { + [auth signInAndRetrieveDataWithCredential:credential + completion:^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { if (error) { [self logFailure:@"sign-in with Email/Password failed" error:error]; [self logFailedTest:@"sign-in with Email/Password should succeed."]; @@ -1381,8 +1382,10 @@ - (void)automatedAccountLinking { callback:^(FIRAuthCredential *credential, NSError *error) { if (credential) { - [result.user linkWithCredential:credential completion:^(FIRUser *user, + [result.user linkAndRetrieveDataWithCredential:credential + completion:^(FIRAuthDataResult *result, NSError *error) { + FIRUser *user = result.user; if (error) { [self logFailure:@"link auth provider failed" error:error]; [self logFailedTest:@"Account needs to be linked to complete the test."]; @@ -1573,9 +1576,9 @@ - (void)updateEmailPasswordWithCompletion:(void(^)(void))completion { [auth signOut:NULL]; FIRAuthCredential *credential = [FIREmailAuthProvider credentialWithEmail:kFakeEmail password:kFakePassword]; - [auth signInWithCredential:credential - completion:^(FIRUser *_Nullable user, - NSError *_Nullable error) { + [auth signInAndRetrieveDataWithCredential:credential + completion:^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { if (error) { [self logFailure:@"sign-in with Email/Password failed" error:error]; [self logFailedTest:@"sign-in with Email/Password should succeed."]; @@ -2003,9 +2006,9 @@ - (void)signInEmailPassword { [FIREmailAuthProvider credentialWithEmail:email password:password]; [self showSpinner:^{ - [[AppManager auth] signInWithCredential:credential - completion:^(FIRUser *_Nullable user, - NSError *_Nullable error) { + [[AppManager auth] signInAndRetrieveDataWithCredential:credential + completion:^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { [self hideSpinner:^{ if (error) { [self logFailure:@"sign-in with Email/Password failed" error:error]; @@ -2033,10 +2036,10 @@ - (void)signInEmailPasswordAuthDataResult { return; } [self showSpinner:^{ - [[AppManager auth] signInAndRetrieveDataWithEmail:email - password:password - completion:^(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error) { + [[AppManager auth] signInWithEmail:email + password:password + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { [self hideSpinner:^{ if (error) { [self logFailure:@"sign-in with Email/Password failed" error:error]; @@ -2270,8 +2273,9 @@ - (void)reauthenticateEmailPassword { } [self showEmailPasswordDialogWithCompletion:^(FIRAuthCredential *credential) { [self showSpinner:^{ - [[self user] reauthenticateWithCredential:credential - completion:^(NSError *_Nullable error) { + [[self user] reauthenticateAndRetrieveDataWithCredential:credential + completion:^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { if (error) { [self logFailure:@"reauthicate with email/password failed" error:error]; } else { @@ -2321,13 +2325,14 @@ - (void)reauthenticate:(id)authProvider retrieveData:(BOOL)retriev } [self showTypicalUIForUserUpdateResultsWithTitle:@"Reauthenticate" error:error]; }; - FIRUserProfileChangeCallback callback = ^(NSError *_Nullable error) { + FIRAuthDataResultCallback callback = ^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { completion(nil, error); }; if (retrieveData) { [user reauthenticateAndRetrieveDataWithCredential:credential completion:completion]; } else { - [user reauthenticateWithCredential:credential completion:callback]; + [user reauthenticateAndRetrieveDataWithCredential:credential completion:callback]; } } }]; @@ -2367,14 +2372,14 @@ - (void)signinWithProvider:(id)authProvider retrieveData:(BOOL)ret } [self showTypicalUIForUserUpdateResultsWithTitle:@"Sign-In" error:error]; }; - FIRAuthResultCallback callback = ^(FIRUser *_Nullable user, - NSError *_Nullable error) { + FIRAuthDataResultCallback callback = ^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { completion(nil, error); }; if (retrieveData) { [auth signInAndRetrieveDataWithCredential:credential completion:completion]; } else { - [auth signInWithCredential:credential completion:callback]; + [auth signInAndRetrieveDataWithCredential:credential completion:callback]; } } }]; @@ -2551,14 +2556,14 @@ - (void)linkWithAuthProvider:(id)authProvider retrieveData:(BOOL)r [self showTypicalUIForUserUpdateResultsWithTitle:@"Link Account" error:error]; } }; - FIRAuthResultCallback callback = ^(FIRUser *_Nullable user, - NSError *_Nullable error) { + FIRAuthDataResultCallback callback = ^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { completion(nil, error); }; if (retrieveData) { [user linkAndRetrieveDataWithCredential:credential completion:completion]; } else { - [user linkWithCredential:credential completion:callback]; + [user linkAndRetrieveDataWithCredential:credential completion:callback]; } } }]; @@ -2602,8 +2607,8 @@ - (void)linkWithFacebookAndRetrieveData { - (void)linkWithEmailPassword { [self showEmailPasswordDialogWithCompletion:^(FIRAuthCredential *credential) { [self showSpinner:^{ - [[self user] linkWithCredential:credential - completion:^(FIRUser *user, NSError *_Nullable error) { + [[self user] linkAndRetrieveDataWithCredential:credential + completion:^(FIRAuthDataResult *result, NSError *error) { if (error) { [self logFailure:@"link Email/Password failed" error:error]; } else { @@ -3108,10 +3113,10 @@ - (void)createUserAuthDataResult { } [self showSpinner:^{ - [[AppManager auth] createUserAndRetrieveDataWithEmail:email - password:password - completion:^(FIRAuthDataResult *_Nullable result, - NSError *_Nullable error) { + [[AppManager auth] createUserWithEmail:email + password:password + completion:^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { if (error) { [self logFailure:@"create user failed" error:error]; } else { @@ -3378,9 +3383,9 @@ - (void)linkPhoneNumber:(NSString *_Nullable)phoneNumber FIRPhoneAuthCredential *credential = [[AppManager phoneAuthProvider] credentialWithVerificationID:verificationID verificationCode:verificationCode]; - [[self user] linkWithCredential:credential - completion:^(FIRUser *_Nullable user, - NSError *_Nullable error) { + [[self user] linkAndRetrieveDataWithCredential:credential + completion:^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { [self hideSpinner:^{ if (error) { if (error.code == FIRAuthErrorCodeCredentialAlreadyInUse) { @@ -3396,9 +3401,9 @@ - (void)linkPhoneNumber:(NSString *_Nullable)phoneNumber [self showSpinner:^{ FIRPhoneAuthCredential *credential = error.userInfo[FIRAuthErrorUserInfoUpdatedCredentialKey]; - [[AppManager auth] signInWithCredential:credential - completion:^(FIRUser *_Nullable user, - NSError *_Nullable error) { + [[AppManager auth] signInAndRetrieveDataWithCredential:credential + completion:^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { [self hideSpinner:^{ if (error) { [self logFailure:@"failed to verify phone number" error:error]; @@ -3467,7 +3472,7 @@ - (void)signInAnonymously { success. */ - (void)signInAnonymouslyAuthDataResult { - [[AppManager auth] signInAnonymouslyAndRetrieveDataWithCompletion: + [[AppManager auth] signInAnonymouslyWithCompletion: ^(FIRAuthDataResult *_Nullable authResult, NSError *_Nullable error) { if (error) { [self logFailure:@"sign-in anonymously failed" error:error]; @@ -3492,9 +3497,9 @@ - (void)signInWithGitHub { FIROAuthCredential *credential = [FIROAuthProvider credentialWithProviderID:FIRGitHubAuthProviderID accessToken:accessToken]; if (credential) { - [[AppManager auth] signInWithCredential:credential - completion:^(FIRUser *_Nullable result, - NSError *_Nullable error) { + [[AppManager auth] signInAndRetrieveDataWithCredential:credential + completion:^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { if (error) { [self logFailure:@"sign-in with provider failed" error:error]; } else { @@ -3660,9 +3665,9 @@ - (void)doSignInWithCustomToken:(NSString *_Nullable)userEnteredTokenText { } - (void)doSignInAndRetrieveDataWithCustomToken:(NSString *_Nullable)userEnteredTokenText { - [[AppManager auth] signInAndRetrieveDataWithCustomToken:userEnteredTokenText - completion:^(FIRAuthDataResult *_Nullable result, - NSError *_Nullable error) { + [[AppManager auth] signInWithCustomToken:userEnteredTokenText + completion:^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { if (error) { [self logFailure:@"sign-in with custom token failed" error:error]; [self showMessagePromptWithTitle:kSignInErrorAlertTitle diff --git a/Firebase/Auth/Source/Auth/FIRAuth.m b/Firebase/Auth/Source/Auth/FIRAuth.m index 9c74a55f141..00fda365ed7 100644 --- a/Firebase/Auth/Source/Auth/FIRAuth.m +++ b/Firebase/Auth/Source/Auth/FIRAuth.m @@ -601,18 +601,6 @@ - (void)signInWithEmail:(NSString *)email }]; } -- (void)signInAndRetrieveDataWithEmail:(NSString *)email - password:(NSString *)password - completion:(nullable FIRAuthDataResultCallback)completion { - dispatch_async(FIRAuthGlobalWorkQueue(), ^{ - FIRAuthDataResultCallback decoratedCallback = - [self signInFlowAuthDataResultCallbackByDecoratingCallback:completion]; - [self internalSignInAndRetrieveDataWithEmail:email - password:password - completion:decoratedCallback]; - }); -} - /** @fn internalSignInAndRetrieveDataWithEmail:password:callback: @brief Signs in using an email address and password. @param email The user's email address. @@ -741,12 +729,8 @@ - (void)internalSignInAndRetrieveDataWithEmail:(nonnull NSString *)email } - (void)signInWithCredential:(FIRAuthCredential *)credential - completion:(nullable FIRAuthResultCallback)completion { - dispatch_async(FIRAuthGlobalWorkQueue(), ^{ - FIRAuthResultCallback callback = - [self signInFlowAuthResultCallbackByDecoratingCallback:completion]; - [self internalSignInWithCredential:credential callback:callback]; - }); + completion:(nullable FIRAuthDataResultCallback)completion { + [self signInAndRetrieveDataWithCredential:credential completion:completion]; } - (void)signInAndRetrieveDataWithCredential:(FIRAuthCredential *)credential @@ -903,57 +887,6 @@ - (void)internalSignInAndRetrieveDataWithCredential:(FIRAuthCredential *)credent }]; } -- (void)signInWithCredential:(FIRAuthCredential *)credential - callback:(FIRAuthResultCallback)callback { - [self signInAndRetrieveDataWithCredential:credential - completion:^(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error) { - callback(authResult.user, error); - }]; -} - -- (void)signInAnonymouslyAndRetrieveDataWithCompletion: - (nullable FIRAuthDataResultCallback)completion { - dispatch_async(FIRAuthGlobalWorkQueue(), ^{ - FIRAuthDataResultCallback decoratedCallback = - [self signInFlowAuthDataResultCallbackByDecoratingCallback:completion]; - if (self->_currentUser.anonymous) { - FIRAdditionalUserInfo *additionalUserInfo = - [[FIRAdditionalUserInfo alloc] initWithProviderID:nil - profile:nil - username:nil - isNewUser:NO]; - FIRAuthDataResult *authDataResult = - [[FIRAuthDataResult alloc] initWithUser:self->_currentUser - additionalUserInfo:additionalUserInfo]; - decoratedCallback(authDataResult, nil); - return; - } - [self internalSignInAnonymouslyWithCompletion:^(FIRSignUpNewUserResponse *_Nullable response, - NSError *_Nullable error) { - if (error) { - decoratedCallback(nil, error); - return; - } - [self completeSignInWithAccessToken:response.IDToken - accessTokenExpirationDate:response.approximateExpirationDate - refreshToken:response.refreshToken - anonymous:YES - callback:^(FIRUser *_Nullable user, NSError *_Nullable error) { - FIRAdditionalUserInfo *additionalUserInfo = - [[FIRAdditionalUserInfo alloc] initWithProviderID:nil - profile:nil - username:nil - isNewUser:YES]; - FIRAuthDataResult *authDataResult = - [[FIRAuthDataResult alloc] initWithUser:user - additionalUserInfo:additionalUserInfo]; - decoratedCallback(authDataResult, nil); - }]; - }]; - }); -} - - (void)signInAnonymouslyWithCompletion:(nullable FIRAuthDataResultCallback)completion { dispatch_async(FIRAuthGlobalWorkQueue(), ^{ FIRAuthDataResultCallback decoratedCallback = @@ -1002,15 +935,6 @@ - (void)signInWithCustomToken:(NSString *)token }); } -- (void)signInAndRetrieveDataWithCustomToken:(NSString *)token - completion:(nullable FIRAuthDataResultCallback)completion { - dispatch_async(FIRAuthGlobalWorkQueue(), ^{ - FIRAuthDataResultCallback decoratedCallback = - [self signInFlowAuthDataResultCallbackByDecoratingCallback:completion]; - [self internalSignInAndRetrieveDataWithCustomToken:token completion:decoratedCallback]; - }); -} - - (void)createUserWithEmail:(NSString *)email password:(NSString *)password completion:(nullable FIRAuthDataResultCallback)completion { @@ -1044,40 +968,6 @@ - (void)createUserWithEmail:(NSString *)email }); } -- (void)createUserAndRetrieveDataWithEmail:(NSString *)email - password:(NSString *)password - completion:(nullable FIRAuthDataResultCallback)completion { - dispatch_async(FIRAuthGlobalWorkQueue(), ^{ - FIRAuthDataResultCallback decoratedCallback = - [self signInFlowAuthDataResultCallbackByDecoratingCallback:completion]; - [self internalCreateUserWithEmail:email - password:password - completion:^(FIRSignUpNewUserResponse *_Nullable response, - NSError *_Nullable error) { - if (error) { - decoratedCallback(nil, error); - return; - } - - [self completeSignInWithAccessToken:response.IDToken - accessTokenExpirationDate:response.approximateExpirationDate - refreshToken:response.refreshToken - anonymous:NO - callback:^(FIRUser *_Nullable user, NSError *_Nullable error) { - FIRAdditionalUserInfo *additionalUserInfo = - [[FIRAdditionalUserInfo alloc] initWithProviderID:FIREmailAuthProviderID - profile:nil - username:nil - isNewUser:YES]; - FIRAuthDataResult *authDataResult = - [[FIRAuthDataResult alloc] initWithUser:user - additionalUserInfo:additionalUserInfo]; - decoratedCallback(authDataResult, nil); - }]; - }]; - }); -} - - (void)confirmPasswordResetWithCode:(NSString *)code newPassword:(NSString *)newPassword completion:(FIRConfirmPasswordResetCallback)completion { diff --git a/Firebase/Auth/Source/Public/FIRAuth.h b/Firebase/Auth/Source/Public/FIRAuth.h index ca567a0112d..be8a7308014 100644 --- a/Firebase/Auth/Source/Public/FIRAuth.h +++ b/Firebase/Auth/Source/Public/FIRAuth.h @@ -39,7 +39,8 @@ NS_ASSUME_NONNULL_BEGIN /** @typedef FIRUserUpdateCallback @brief The type of block invoked when a request to update the current user is completed. */ -typedef void (^FIRUserUpdateCallback)(NSError *_Nullable error) NS_SWIFT_NAME(UserUpdateCallback); +typedef void (^FIRUserUpdateCallback)(NSError *_Nullable error) + NS_SWIFT_NAME(UserUpdateCallback); /** @typedef FIRAuthStateDidChangeListenerHandle @brief The type of handle returned by `FIRAuth.addAuthStateDidChangeListener:`. @@ -409,68 +410,6 @@ NS_SWIFT_NAME(Auth) link:(NSString *)link completion:(nullable FIRAuthDataResultCallback)completion; -/** @fn signInAndRetrieveDataWithEmail:password:completion: - @brief Please use `signInWithEmail:password:completion:` for Objective-C or - `signIn(withEmail:password:completion:)` for Swift instead. - - @param email The user's email address. - @param password The user's password. - @param completion Optionally; a block which is invoked when the sign in flow finishes, or is - canceled. Invoked asynchronously on the main thread in the future. - */ -- (void)signInAndRetrieveDataWithEmail:(NSString *)email - password:(NSString *)password - completion:(nullable FIRAuthDataResultCallback)completion - DEPRECATED_MSG_ATTRIBUTE( - "Please use signInWithEmail:password:completion: for" - " Objective-C or signIn(withEmail:password:completion:) for" - " Swift instead."); - -/** @fn signInWithCredential:completion: - @brief Please use `signInAndRetrieveDataWithCredential:completion:` for Objective-C or - `signInAndRetrieveData(with:completion:)` for swift instead - - @param credential The credential supplied by the IdP. - @param completion Optionally; a block which is invoked when the sign in flow finishes, or is - canceled. Invoked asynchronously on the main thread in the future. - - @remarks Possible error codes: - - + `FIRAuthErrorCodeInvalidCredential` - Indicates the supplied credential is invalid. - This could happen if it has expired or it is malformed. - + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that accounts - with the identity provider represented by the credential are not enabled. - Enable them in the Auth section of the Firebase console. - + `FIRAuthErrorCodeAccountExistsWithDifferentCredential` - Indicates the email asserted - by the credential (e.g. the email in a Facebook access token) is already in use by an - existing account, that cannot be authenticated with this sign-in method. Call - fetchProvidersForEmail for this user’s email and then prompt them to sign in with any of - the sign-in providers returned. This error will only be thrown if the "One account per - email address" setting is enabled in the Firebase console, under Auth settings. - + `FIRAuthErrorCodeUserDisabled` - Indicates the user's account is disabled. - + `FIRAuthErrorCodeWrongPassword` - Indicates the user attempted sign in with an - incorrect password, if credential is of the type EmailPasswordAuthCredential. - + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed. - + `FIRAuthErrorCodeMissingVerificationID` - Indicates that the phone auth credential was - created with an empty verification ID. - + `FIRAuthErrorCodeMissingVerificationCode` - Indicates that the phone auth credential - was created with an empty verification code. - + `FIRAuthErrorCodeInvalidVerificationCode` - Indicates that the phone auth credential - was created with an invalid verification Code. - + `FIRAuthErrorCodeInvalidVerificationID` - Indicates that the phone auth credential was - created with an invalid verification ID. - + `FIRAuthErrorCodeSessionExpired` - Indicates that the SMS code has expired. - - - - @remarks See `FIRAuthErrors` for a list of error codes that are common to all API methods - */ -- (void)signInWithCredential:(FIRAuthCredential *)credential - completion:(nullable FIRAuthResultCallback)completion DEPRECATED_MSG_ATTRIBUTE( - "Please use signInAndRetrieveDataWithCredential:completion:" - " for Objective-C or signInAndRetrieveData(with:completion:)" - " for Swift instead."); - /** @fn signInWithProvider:UIDelegate:completion: @brief Signs in using the provided auth provider instance. @@ -519,6 +458,15 @@ NS_SWIFT_NAME(Auth) UIDelegate:(nullable id)UIDelegate completion:(nullable FIRAuthDataResultCallback)completion; +/** @fn signInAndRetrieveDataWithCredential:completion: + @brief Please use signInWithCredential:completion: for Objective-C or " + "signIn(with:completion:) for Swift instead. + */ +- (void)signInAndRetrieveDataWithCredential:(FIRAuthCredential *)credential + completion:(nullable FIRAuthDataResultCallback)completion +DEPRECATED_MSG_ATTRIBUTE("Please use signInWithCredential:completion: for Objective-C or " + "signIn(with:completion:) for Swift instead."); + /** @fn signInAndRetrieveDataWithCredential: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 @@ -530,37 +478,35 @@ NS_SWIFT_NAME(Auth) @remarks Possible error codes: - + `FIRAuthErrorCodeInvalidCredential` - Indicates the supplied credential is invalid. - This could happen if it has expired or it is malformed. - + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that accounts - with the identity provider represented by the credential are not enabled. - Enable them in the Auth section of the Firebase console. - + `FIRAuthErrorCodeAccountExistsWithDifferentCredential` - Indicates the email asserted - by the credential (e.g. the email in a Facebook access token) is already in use by an - existing account, that cannot be authenticated with this sign-in method. Call - fetchProvidersForEmail for this user’s email and then prompt them to sign in with any of - the sign-in providers returned. This error will only be thrown if the "One account per - email address" setting is enabled in the Firebase console, under Auth settings. - + `FIRAuthErrorCodeUserDisabled` - Indicates the user's account is disabled. - + `FIRAuthErrorCodeWrongPassword` - Indicates the user attempted sign in with an - incorrect password, if credential is of the type EmailPasswordAuthCredential. - + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed. - + `FIRAuthErrorCodeMissingVerificationID` - Indicates that the phone auth credential was - created with an empty verification ID. - + `FIRAuthErrorCodeMissingVerificationCode` - Indicates that the phone auth credential - was created with an empty verification code. - + `FIRAuthErrorCodeInvalidVerificationCode` - Indicates that the phone auth credential - was created with an invalid verification Code. - + `FIRAuthErrorCodeInvalidVerificationID` - Indicates that the phone auth credential was - created with an invalid verification ID. - + `FIRAuthErrorCodeSessionExpired` - Indicates that the SMS code has expired. - - + + `FIRAuthErrorCodeInvalidCredential` - Indicates the supplied credential is invalid. + This could happen if it has expired or it is malformed. + + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that accounts + with the identity provider represented by the credential are not enabled. + Enable them in the Auth section of the Firebase console. + + `FIRAuthErrorCodeAccountExistsWithDifferentCredential` - Indicates the email asserted + by the credential (e.g. the email in a Facebook access token) is already in use by an + existing account, that cannot be authenticated with this sign-in method. Call + fetchProvidersForEmail for this user’s email and then prompt them to sign in with any of + the sign-in providers returned. This error will only be thrown if the "One account per + email address" setting is enabled in the Firebase console, under Auth settings. + + `FIRAuthErrorCodeUserDisabled` - Indicates the user's account is disabled. + + `FIRAuthErrorCodeWrongPassword` - Indicates the user attempted sign in with an + incorrect password, if credential is of the type EmailPasswordAuthCredential. + + `FIRAuthErrorCodeInvalidEmail` - Indicates the email address is malformed. + + `FIRAuthErrorCodeMissingVerificationID` - Indicates that the phone auth credential was + created with an empty verification ID. + + `FIRAuthErrorCodeMissingVerificationCode` - Indicates that the phone auth credential + was created with an empty verification code. + + `FIRAuthErrorCodeInvalidVerificationCode` - Indicates that the phone auth credential + was created with an invalid verification Code. + + `FIRAuthErrorCodeInvalidVerificationID` - Indicates that the phone auth credential was + created with an invalid verification ID. + + `FIRAuthErrorCodeSessionExpired` - Indicates that the SMS code has expired. @remarks See `FIRAuthErrors` for a list of error codes that are common to all API methods - */ -- (void)signInAndRetrieveDataWithCredential:(FIRAuthCredential *)credential - completion:(nullable FIRAuthDataResultCallback)completion; +*/ +- (void)signInWithCredential:(FIRAuthCredential *)credential + completion:(nullable FIRAuthDataResultCallback)completion; /** @fn signInAnonymouslyWithCompletion: @brief Asynchronously creates and becomes an anonymous user. @@ -579,17 +525,6 @@ NS_SWIFT_NAME(Auth) */ - (void)signInAnonymouslyWithCompletion:(nullable FIRAuthDataResultCallback)completion; -/** @fn signInAnonymouslyAndRetrieveDataWithCompletion: - @brief `Please use sign `signInAnonymouslyWithCompletion:` for Objective-C or - `signInAnonymously(Completion:)` for Swift instead. - @param completion Optionally; a block which is invoked when the sign in finishes, or is - canceled. Invoked asynchronously on the main thread in the future. - */ -- (void)signInAnonymouslyAndRetrieveDataWithCompletion: - (nullable FIRAuthDataResultCallback)completion - DEPRECATED_MSG_ATTRIBUTE("Please use signInAnonymouslyWithCompletion: for Objective-C or" - " signInAnonymously(Completion:) for swift instead."); - /** @fn signInWithCustomToken:completion: @brief Asynchronously signs in to Firebase with the given Auth token. @@ -604,28 +539,11 @@ NS_SWIFT_NAME(Auth) + `FIRAuthErrorCodeCustomTokenMismatch` - Indicates the service account and the API key belong to different projects. - - @remarks See `FIRAuthErrors` for a list of error codes that are common to all API methods. */ - (void)signInWithCustomToken:(NSString *)token completion:(nullable FIRAuthDataResultCallback)completion; -/** @fn signInAndRetrieveDataWithCustomToken:completion: - @brief Please use `signInWithCustomToken:completion:` or `signIn(withCustomToken:completion:)` - for Swift instead. - - @param token A self-signed custom auth token. - @param completion Optionally; a block which is invoked when the sign in finishes, or is - canceled. Invoked asynchronously on the main thread in the future. - */ -- (void)signInAndRetrieveDataWithCustomToken:(NSString *)token - completion:(nullable FIRAuthDataResultCallback)completion - DEPRECATED_MSG_ATTRIBUTE( - "Please use signInWithCustomToken:completion:" - "for Objective-C or signIn(withCustomToken:completion:) for" - " Swift instead."); - /** @fn createUserWithEmail:password:completion: @brief Creates and, on success, signs in a user with the given email address and password. @@ -652,23 +570,6 @@ NS_SWIFT_NAME(Auth) password:(NSString *)password completion:(nullable FIRAuthDataResultCallback)completion; -/** @fn createUserAndRetrieveDataWithEmail:password:completion: - @brief Please use `createUserAndRetrieveDataWithEmail:password:completion:` or - `createUser(withEmail:password:completion:)` for Swift instead. - - @param email The user's email address. - @param password The user's desired password. - @param completion Optionally; a block which is invoked when the sign up flow finishes, or is - canceled. Invoked asynchronously on the main thread in the future. - */ -- (void)createUserAndRetrieveDataWithEmail:(NSString *)email - password:(NSString *)password - completion:(nullable FIRAuthDataResultCallback)completion - DEPRECATED_MSG_ATTRIBUTE( - "Please use createUserWithEmail:password:completion: for" - " Objective-C or createUser(withEmail:password:completion:)" - " for Swift instead."); - /** @fn confirmPasswordResetWithCode:newPassword:completion: @brief Resets the password given a code sent to the user outside of the app and a new password for the user. diff --git a/Firebase/Auth/Source/Public/FIRAuthErrors.h b/Firebase/Auth/Source/Public/FIRAuthErrors.h index 2c90274e5b8..63cd3432b60 100644 --- a/Firebase/Auth/Source/Public/FIRAuthErrors.h +++ b/Firebase/Auth/Source/Public/FIRAuthErrors.h @@ -44,20 +44,6 @@ NS_SWIFT_NAME(AuthErrors) */ extern NSString *const FIRAuthErrorDomain NS_SWIFT_NAME(AuthErrorDomain); -/** - @brief Please use `FIRAuthErrorUserInfoUpdatedCredentialKey` for Objective C or - `AuthErrorUserInfoUpdatedCredentialKey` for Swift instead. - */ -extern NSString *const FIRAuthUpdatedCredentialKey - NS_SWIFT_NAME(AuthUpdatedCredentialKey) __attribute__((deprecated)); - -/** - @brief Please use `FIRAuthErrorUserInfoNameKey` for Objective C or - `AuthErrorUserInfoNameKey` for Swift instead. - */ -extern NSString *const FIRAuthErrorNameKey - NS_SWIFT_NAME(AuthErrorNameKey) __attribute__((deprecated)); - /** @brief The name of the key for the error short string of an error code. */ diff --git a/Firebase/Auth/Source/Public/FIREmailAuthProvider.h b/Firebase/Auth/Source/Public/FIREmailAuthProvider.h index b6375bd2a69..bb8f85dc2f4 100644 --- a/Firebase/Auth/Source/Public/FIREmailAuthProvider.h +++ b/Firebase/Auth/Source/Public/FIREmailAuthProvider.h @@ -33,13 +33,7 @@ extern NSString *const FIREmailLinkAuthSignInMethod NS_SWIFT_NAME(EmailLinkAuthS /** @brief A string constant identifying the email & password sign-in method. */ -extern NSString *const FIREmailPasswordAuthSignInMethod - NS_SWIFT_NAME(EmailPasswordAuthSignInMethod); - -/** - @brief Please use `FIREmailAuthProviderID` for Objective-C or `EmailAuthProviderID` for Swift instead. - */ -extern NSString *const FIREmailPasswordAuthProviderID __attribute__((deprecated)); +extern NSString *const FIREmailPasswordAuthSignInMethod NS_SWIFT_NAME(EmailPasswordAuthSignInMethod); /** @class FIREmailAuthProvider @brief A concrete implementation of `FIRAuthProvider` for Email & Password Sign In. @@ -47,12 +41,6 @@ extern NSString *const FIREmailPasswordAuthProviderID __attribute__((deprecated) NS_SWIFT_NAME(EmailAuthProvider) @interface FIREmailAuthProvider : NSObject -/** @typedef FIREmailPasswordAuthProvider - @brief Please use `FIREmailAuthProvider` instead. - */ -typedef FIREmailAuthProvider FIREmailPasswordAuthProvider __attribute__((deprecated)); - - /** @fn credentialWithEmail:password: @brief Creates an `FIRAuthCredential` for an email & password sign in. diff --git a/Firebase/Auth/Source/Public/FIROAuthProvider.h b/Firebase/Auth/Source/Public/FIROAuthProvider.h index e921e27286d..57635e94e20 100644 --- a/Firebase/Auth/Source/Public/FIROAuthProvider.h +++ b/Firebase/Auth/Source/Public/FIROAuthProvider.h @@ -23,18 +23,6 @@ NS_ASSUME_NONNULL_BEGIN -/** - @brief A string constant identifying the Microsoft identity provider. - */ -extern NSString *const FIRMicrosoftAuthProviderID NS_SWIFT_NAME(MicrosoftAuthProviderID) - DEPRECATED_MSG_ATTRIBUTE("Please use \"microsoft.com\" instead."); - -/** - @brief A string constant identifying the Yahoo identity provider. - */ -extern NSString *const FIRYahooAuthProviderID NS_SWIFT_NAME(YahooAuthProviderID) - DEPRECATED_MSG_ATTRIBUTE("Please use \"yahoo.com\" instead."); - /** @class FIROAuthProvider @brief A concrete implementation of `FIRAuthProvider` for generic OAuth Providers. */ diff --git a/Firebase/Auth/Source/Public/FIRUser.h b/Firebase/Auth/Source/Public/FIRUser.h index cc5d0a00120..caf05e1006f 100644 --- a/Firebase/Auth/Source/Public/FIRUser.h +++ b/Firebase/Auth/Source/Public/FIRUser.h @@ -221,18 +221,6 @@ NS_SWIFT_NAME(User) - (void)reloadWithCompletion:(nullable FIRUserProfileChangeCallback)completion; /** @fn reauthenticateWithCredential:completion: - @brief Please use reauthenticateAndRetrieveDataWithCredential:completion: for Objective-C or - reauthenticateAndRetrieveData(WithCredential:completion:) for Swift instead. - */ -- (void)reauthenticateWithCredential:(FIRAuthCredential *)credential - completion:(nullable FIRUserProfileChangeCallback)completion - DEPRECATED_MSG_ATTRIBUTE( "Please use" - " reauthenticateAndRetrieveDataWithCredential:completion: for" - " Objective-C or" - " reauthenticateAndRetrieveData(WithCredential:completion:)" - " for Swift instead."); - -/** @fn reauthenticateAndRetrieveDataWithCredential:completion: @brief Renews the user's authentication tokens by validating a fresh set of credentials supplied by the user and returns additional identity provider data. @@ -268,8 +256,18 @@ NS_SWIFT_NAME(User) @remarks See `FIRAuthErrors` for a list of error codes that are common to all API methods. */ -- (void)reauthenticateAndRetrieveDataWithCredential:(FIRAuthCredential *) credential - completion:(nullable FIRAuthDataResultCallback) completion; +- (void)reauthenticateWithCredential:(FIRAuthCredential *)credential + completion:(nullable FIRAuthDataResultCallback)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 FIRAuthDataResultCallback)completion +DEPRECATED_MSG_ATTRIBUTE( "Please use reauthenticateWithCredential:completion: for" + " Objective-C or reauthenticate(withCredential:completion:)" + " for Swift instead."); /** @fn getIDTokenResultWithCompletion: @brief Retrieves the Firebase authentication token, possibly refreshing it if it has expired. @@ -326,20 +324,18 @@ NS_SWIFT_NAME(User) - (void)getIDTokenForcingRefresh:(BOOL)forceRefresh completion:(nullable FIRAuthTokenCallback)completion; -/** @fn linkWithCredential:completion: - @brief Please use linkAndRetrieveDataWithCredential:completion: for Objective-C or - linkAndRetrieveData(WithCredential:completion:) for Swift instead. +/** @fn linkAndRetrieveDataWithCredential:completion: + @brief Please use linkWithCredential:completion: for Objective-C " + "or link(withCredential:completion:) for Swift instead. */ -- (void)linkWithCredential:(FIRAuthCredential *)credential - completion:(nullable FIRAuthResultCallback)completion DEPRECATED_MSG_ATTRIBUTE( - "Please use linkAndRetrieveDataWithCredential:completion: for" - " Objective-C or" - " linkAndRetrieveData(WithCredential:completion:) for" - " Swift instead."); +- (void)linkAndRetrieveDataWithCredential:(FIRAuthCredential *)credential + completion:(nullable FIRAuthDataResultCallback)completion +DEPRECATED_MSG_ATTRIBUTE("Please use linkWithCredential:completion: for Objective-C " + "or link(withCredential:completion:) for Swift instead."); -/** @fn linkAndRetrieveDataWithCredential:completion: +/** @fn linkWithCredential:completion: @brief Associates a user account from a third-party identity provider with this user and - returns additional identity provider data. + returns additional identity provider data. @param credential The credential for the identity provider. @param completion Optionally; the block invoked when the unlinking is complete, or fails. @@ -350,19 +346,18 @@ NS_SWIFT_NAME(User) + `FIRAuthErrorCodeProviderAlreadyLinked` - Indicates an attempt to link a provider of a type already linked to this account. + `FIRAuthErrorCodeCredentialAlreadyInUse` - Indicates an attempt to link with a - credential - that has already been linked with a different Firebase account. + credential that has already been linked with a different Firebase account. + `FIRAuthErrorCodeOperationNotAllowed` - Indicates that accounts with the identity provider represented by the credential are not enabled. Enable them in the Auth section of the Firebase console. @remarks This method may also return error codes associated with updateEmail:completion: and - updatePassword:completion: on FIRUser. + updatePassword:completion: on FIRUser. @remarks See `FIRAuthErrors` for a list of error codes that are common to all FIRUser methods. */ -- (void)linkAndRetrieveDataWithCredential:(FIRAuthCredential *) credential - completion:(nullable FIRAuthDataResultCallback) completion; +- (void)linkWithCredential:(FIRAuthCredential *)credential + completion:(nullable FIRAuthDataResultCallback)completion; /** @fn unlinkFromProvider:completion: @brief Disassociates a user account from a third-party identity provider with this user. diff --git a/Firebase/Auth/Source/User/FIRUser.m b/Firebase/Auth/Source/User/FIRUser.m index c822595e87c..b5fd1198226 100644 --- a/Firebase/Auth/Source/User/FIRUser.m +++ b/Firebase/Auth/Source/User/FIRUser.m @@ -750,18 +750,12 @@ - (void)reloadWithCompletion:(nullable FIRUserProfileChangeCallback)completion { #pragma mark - -- (void)reauthenticateWithCredential:(FIRAuthCredential *)credential - completion:(nullable FIRUserProfileChangeCallback)completion { - FIRAuthDataResultCallback callback = ^(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error) { - completion(error); - }; - [self reauthenticateAndRetrieveDataWithCredential:credential completion:callback]; +- (void)reauthenticateWithCredential:(FIRAuthCredential *) credential + completion:(nullable FIRAuthDataResultCallback) completion { + [self reauthenticateAndRetrieveDataWithCredential:credential completion:completion]; } - -- (void) - reauthenticateAndRetrieveDataWithCredential:(FIRAuthCredential *) credential - completion:(nullable FIRAuthDataResultCallback) completion { +- (void)reauthenticateAndRetrieveDataWithCredential:(FIRAuthCredential *) credential + completion:(nullable FIRAuthDataResultCallback) completion { dispatch_async(FIRAuthGlobalWorkQueue(), ^{ [self->_auth internalSignInAndRetrieveDataWithCredential:credential isReauthentication:YES @@ -973,12 +967,8 @@ - (void)internalGetTokenForcingRefresh:(BOOL)forceRefresh } - (void)linkWithCredential:(FIRAuthCredential *)credential - completion:(nullable FIRAuthResultCallback)completion { - FIRAuthDataResultCallback callback = ^(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error) { - completion(authResult.user, error); - }; - [self linkAndRetrieveDataWithCredential:credential completion:callback]; + completion:(nullable FIRAuthDataResultCallback)completion { + [self linkAndRetrieveDataWithCredential:credential completion:completion]; } - (void)linkAndRetrieveDataWithCredential:(FIRAuthCredential *)credential From db176736ef5cb9877b629c367c87efbac192643a Mon Sep 17 00:00:00 2001 From: Chuan Ren Date: Thu, 4 Apr 2019 12:03:22 -0700 Subject: [PATCH 2/4] Clean deprecated apis --- Firebase/Auth/Source/Public/FIRAuth.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Firebase/Auth/Source/Public/FIRAuth.h b/Firebase/Auth/Source/Public/FIRAuth.h index be8a7308014..7d0847ea189 100644 --- a/Firebase/Auth/Source/Public/FIRAuth.h +++ b/Firebase/Auth/Source/Public/FIRAuth.h @@ -467,7 +467,7 @@ NS_SWIFT_NAME(Auth) DEPRECATED_MSG_ATTRIBUTE("Please use signInWithCredential:completion: for Objective-C or " "signIn(with:completion:) for Swift instead."); -/** @fn signInAndRetrieveDataWithCredential:completion: +/** @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 identity provider data. From 24926fe7477632cb7f58ca6817f4fc2720e74fc7 Mon Sep 17 00:00:00 2001 From: Chuan Ren Date: Thu, 4 Apr 2019 14:08:42 -0700 Subject: [PATCH 3/4] Fix test cases --- Example/Auth/ApiTests/FacebookAuthTests.m | 4 +- Example/Auth/ApiTests/GoogleAuthTests.m | 2 +- Example/Auth/ApiTests/GoogleAuthTests.swift | 2 +- Example/Auth/Tests/FIRAuthTests.m | 112 +++++------ Example/Auth/Tests/FIRUserTests.m | 197 +++++++++----------- Firebase/Auth/Source/Auth/FIRAuth.m | 3 + Firebase/Auth/Source/User/FIRUser.m | 7 + 7 files changed, 162 insertions(+), 165 deletions(-) diff --git a/Example/Auth/ApiTests/FacebookAuthTests.m b/Example/Auth/ApiTests/FacebookAuthTests.m index cb74fe71461..b21c47e1650 100644 --- a/Example/Auth/ApiTests/FacebookAuthTests.m +++ b/Example/Auth/ApiTests/FacebookAuthTests.m @@ -54,7 +54,7 @@ - (void)testSignInWithFaceboook { XCTestExpectation *expectation = [self expectationWithDescription:@"Facebook sign-in finished."]; [auth signInWithCredential:credential - completion:^(FIRUser *user, NSError *error) { + completion:^(FIRAuthDataResult *result, NSError *error) { if (error) { NSLog(@"Facebook sign in error: %@", error); } @@ -94,7 +94,7 @@ - (void)testLinkAnonymousAccountToFacebookAccount { XCTestExpectation *expectation = [self expectationWithDescription:@"Facebook linking finished."]; [auth.currentUser linkWithCredential:credential - completion:^(FIRUser *user, NSError *error) { + completion:^(FIRAuthDataResult *result, NSError *error) { if (error) { NSLog(@"Link to Facebok error: %@", error); } diff --git a/Example/Auth/ApiTests/GoogleAuthTests.m b/Example/Auth/ApiTests/GoogleAuthTests.m index 4611a1b8edf..0d176e02f39 100644 --- a/Example/Auth/ApiTests/GoogleAuthTests.m +++ b/Example/Auth/ApiTests/GoogleAuthTests.m @@ -48,7 +48,7 @@ - (void)testSignInWithGoogle { XCTestExpectation *expectation = [self expectationWithDescription:@"Signing in with Google finished."]; [auth signInWithCredential:credential - completion:^(FIRUser *user, NSError *error) { + completion:^(FIRAuthDataResult *result, NSError *error) { if (error) { NSLog(@"Signing in with Google had error: %@", error); } diff --git a/Example/Auth/ApiTests/GoogleAuthTests.swift b/Example/Auth/ApiTests/GoogleAuthTests.swift index 9a2126ca614..c0f6ecb5fea 100644 --- a/Example/Auth/ApiTests/GoogleAuthTests.swift +++ b/Example/Auth/ApiTests/GoogleAuthTests.swift @@ -35,7 +35,7 @@ class GoogleAuthTestsSwift: FIRAuthApiTestsBase { let credential = GoogleAuthProvider.credential(withIDToken: googleIdToken, accessToken: googleAccessToken) let expectation = self.expectation(description: "Signing in with Google finished.") - auth.signInAndRetrieveData(with: credential) { _, error in + auth.signIn(with: credential) { _, error in if error != nil { print("Signing in with Google had error: %@", error!) } diff --git a/Example/Auth/Tests/FIRAuthTests.m b/Example/Auth/Tests/FIRAuthTests.m index 557447a8a58..a6e8f386004 100644 --- a/Example/Auth/Tests/FIRAuthTests.m +++ b/Example/Auth/Tests/FIRAuthTests.m @@ -375,7 +375,7 @@ - (void)testFetchProvidersForEmailSuccessDeprecatedProviderID { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" NSArray *allProviders = - @[ FIRGoogleAuthProviderID, FIREmailPasswordAuthProviderID ]; + @[ FIRGoogleAuthProviderID, FIREmailAuthProviderID ]; #pragma clang diagnostic pop OCMExpect([_mockBackend createAuthURI:[OCMArg any] callback:[OCMArg any]]) @@ -468,9 +468,9 @@ - (void)testPhoneAuthSuccess { [[FIRPhoneAuthProvider provider] credentialWithVerificationID:kVerificationID verificationCode:kVerificationCode]; - [[FIRAuth auth] signInAndRetrieveDataWithCredential:credential - completion:^(FIRAuthDataResult *_Nullable authDataResult, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithCredential:credential + completion:^(FIRAuthDataResult *_Nullable authDataResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUser:authDataResult.user]; XCTAssertTrue(authDataResult.additionalUserInfo.isNewUser); @@ -494,10 +494,10 @@ - (void)testPhoneAuthMissingVerificationCode { [[FIRPhoneAuthProvider provider] credentialWithVerificationID:kVerificationID verificationCode:@""]; - [[FIRAuth auth] signInWithCredential:credential completion:^(FIRUser *_Nullable user, + [[FIRAuth auth] signInWithCredential:credential completion:^(FIRAuthDataResult * _Nullable result, NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); - XCTAssertNil(user); + XCTAssertNil(result); XCTAssertEqual(error.code, FIRAuthErrorCodeMissingVerificationCode); [expectation fulfill]; }]; @@ -516,10 +516,10 @@ - (void)testPhoneAuthMissingVerificationID { [[FIRPhoneAuthProvider provider] credentialWithVerificationID:@"" verificationCode:kVerificationCode]; - [[FIRAuth auth] signInWithCredential:credential completion:^(FIRUser *_Nullable user, + [[FIRAuth auth] signInWithCredential:credential completion:^(FIRAuthDataResult * _Nullable result, NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); - XCTAssertNil(user); + XCTAssertNil(result); XCTAssertEqual(error.code, FIRAuthErrorCodeMissingVerificationID); [expectation fulfill]; }]; @@ -700,10 +700,9 @@ - (void)testSignInAndRetrieveDataWithEmailPasswordSuccess { [self expectGetAccountInfo]; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [[FIRAuth auth] signOut:NULL]; - [[FIRAuth auth] signInAndRetrieveDataWithEmail:kEmail - password:kFakePassword - completion:^(FIRAuthDataResult *_Nullable result, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithEmail:kEmail + password:kFakePassword + completion:^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUser:result.user]; XCTAssertFalse(result.additionalUserInfo.isNewUser); @@ -724,10 +723,9 @@ - (void)testSignInAndRetrieveDataWithEmailPasswordFailure { .andDispatchError2([FIRAuthErrorUtils wrongPasswordErrorWithMessage:nil]); XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [[FIRAuth auth] signOut:NULL]; - [[FIRAuth auth] signInAndRetrieveDataWithEmail:kEmail - password:kFakePassword - completion:^(FIRAuthDataResult *_Nullable result, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithEmail:kEmail + password:kFakePassword + completion:^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNil(result); XCTAssertEqual(error.code, FIRAuthErrorCodeWrongPassword); @@ -976,9 +974,9 @@ - (void)testSignInWithEmailLinkCredentialSuccess { [[FIRAuth auth] signOut:NULL]; FIRAuthCredential *emailCredential = [FIREmailAuthProvider credentialWithEmail:kEmail link:kFakeEmailSignInlink]; - [[FIRAuth auth] signInAndRetrieveDataWithCredential:emailCredential - completion:^(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithCredential:emailCredential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNotNil(authResult.user); XCTAssertEqualObjects(authResult.user.refreshToken, kRefreshToken); @@ -1004,10 +1002,10 @@ - (void)testSignInWithEmailLinkCredentialFailure { FIRAuthCredential *emailCredential = [FIREmailAuthProvider credentialWithEmail:kEmail link:kFakeEmailSignInlink]; [[FIRAuth auth] signInWithCredential:emailCredential - completion:^(FIRUser *_Nullable user, + completion:^(FIRAuthDataResult * _Nullable result, NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); - XCTAssertNil(user); + XCTAssertNil(result); XCTAssertEqual(error.code, FIRAuthErrorCodeUserDisabled); XCTAssertNotNil(error.userInfo[NSLocalizedDescriptionKey]); [expectation fulfill]; @@ -1041,10 +1039,10 @@ - (void)testSignInWithEmailCredentialSuccess { FIRAuthCredential *emailCredential = [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword]; [[FIRAuth auth] signInWithCredential:emailCredential - completion:^(FIRUser *_Nullable user, + completion:^(FIRAuthDataResult * _Nullable result, NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); - [self assertUser:user]; + [self assertUser:result.user]; XCTAssertNil(error); [expectation fulfill]; }]; @@ -1077,13 +1075,13 @@ - (void)testSignInWithEmailCredentialSuccessWithDepricatedProvider { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" FIRAuthCredential *emailCredential = - [FIREmailPasswordAuthProvider credentialWithEmail:kEmail password:kFakePassword]; + [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword]; #pragma clang diagnostic pop [[FIRAuth auth] signInWithCredential:emailCredential - completion:^(FIRUser *_Nullable user, + completion:^(FIRAuthDataResult * _Nullable result, NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); - [self assertUser:user]; + [self assertUser:result.user]; XCTAssertNil(error); [expectation fulfill]; }]; @@ -1104,10 +1102,10 @@ - (void)testSignInWithEmailCredentialFailure { FIRAuthCredential *emailCredential = [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword]; [[FIRAuth auth] signInWithCredential:emailCredential - completion:^(FIRUser *_Nullable user, + completion:^(FIRAuthDataResult * _Nullable result, NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); - XCTAssertNil(user); + XCTAssertNil(result); XCTAssertEqual(error.code, FIRAuthErrorCodeUserDisabled); XCTAssertNotNil(error.userInfo[NSLocalizedDescriptionKey]); [expectation fulfill]; @@ -1130,7 +1128,8 @@ - (void)testSignInWithEmailCredentialEmptyPassword { FIRAuthCredential *emailCredential = [FIREmailAuthProvider credentialWithEmail:kEmail password:emptyString]; [[FIRAuth auth] signInWithCredential:emailCredential - completion:^(FIRUser *_Nullable user, NSError *_Nullable error) { + completion:^(FIRAuthDataResult * _Nullable result, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertEqual(error.code, FIRAuthErrorCodeWrongPassword); [expectation fulfill]; @@ -1250,7 +1249,7 @@ - (void)testSignInWithGoogleAccountExistsError { FIRAuthCredential *googleCredential = [FIRGoogleAuthProvider credentialWithIDToken:kGoogleIDToken accessToken:kGoogleAccessToken]; [[FIRAuth auth] signInWithCredential:googleCredential - completion:^(FIRUser *_Nullable user, + completion:^(FIRAuthDataResult * _Nullable result, NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertEqual(error.code, FIRAuthErrorCodeAccountExistsWithDifferentCredential); @@ -1290,10 +1289,10 @@ - (void)testSignInWithGoogleCredentialSuccess { FIRAuthCredential *googleCredential = [FIRGoogleAuthProvider credentialWithIDToken:kGoogleIDToken accessToken:kGoogleAccessToken]; [[FIRAuth auth] signInWithCredential:googleCredential - completion:^(FIRUser *_Nullable user, + completion:^(FIRAuthDataResult * _Nullable result, NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); - [self assertUserGoogle:user]; + [self assertUserGoogle:result.user]; XCTAssertNil(error); [expectation fulfill]; }]; @@ -1346,10 +1345,11 @@ - (void)testSignInWithOAuthCredentialSuccess { FIROAuthCredential *OAuthCredential = (FIROAuthCredential *)credential; XCTAssertEqualObjects(OAuthCredential.OAuthResponseURLString, kOAuthRequestURI); XCTAssertEqualObjects(OAuthCredential.sessionID, kOAuthSessionID); - [[FIRAuth auth] signInWithCredential:OAuthCredential completion:^(FIRUser *_Nullable user, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithCredential:OAuthCredential + completion:^(FIRAuthDataResult * _Nullable result, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); - [self assertUserGoogle:user]; + [self assertUserGoogle:result.user]; XCTAssertNil(error); [expectation fulfill]; }]; @@ -1390,9 +1390,9 @@ - (void)testSignInAndRetrieveDataWithCredentialSuccess { [[FIRAuth auth] signOut:NULL]; FIRAuthCredential *googleCredential = [FIRGoogleAuthProvider credentialWithIDToken:kGoogleIDToken accessToken:kGoogleAccessToken]; - [[FIRAuth auth] signInAndRetrieveDataWithCredential:googleCredential - completion:^(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithCredential:googleCredential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUserGoogle:authResult.user]; XCTAssertEqualObjects(authResult.additionalUserInfo.profile, [[self class] googleProfile]); @@ -1418,10 +1418,10 @@ - (void)testSignInWithGoogleCredentialFailure { FIRAuthCredential *googleCredential = [FIRGoogleAuthProvider credentialWithIDToken:kGoogleIDToken accessToken:kGoogleAccessToken]; [[FIRAuth auth] signInWithCredential:googleCredential - completion:^(FIRUser *_Nullable user, + completion:^(FIRAuthDataResult * _Nullable result, NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); - XCTAssertNil(user); + XCTAssertNil(result.user); XCTAssertEqual(error.code, FIRAuthErrorCodeEmailAlreadyInUse); XCTAssertNotNil(error.userInfo[NSLocalizedDescriptionKey]); [expectation fulfill]; @@ -1504,7 +1504,7 @@ - (void)testSignInAnonymouslyAndRetrieveDataSuccess { [self expectGetAccountInfoAnonymous]; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [[FIRAuth auth] signOut:NULL]; - [[FIRAuth auth] signInAnonymouslyAndRetrieveDataWithCompletion: + [[FIRAuth auth] signInAnonymouslyWithCompletion: ^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUserAnonymous:result.user]; @@ -1524,7 +1524,7 @@ - (void)testSignInAnonymouslyAndRetrieveDataFailure { .andDispatchError2([FIRAuthErrorUtils operationNotAllowedErrorWithMessage:nil]); XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [[FIRAuth auth] signOut:NULL]; - [[FIRAuth auth] signInAnonymouslyAndRetrieveDataWithCompletion: + [[FIRAuth auth] signInAnonymouslyWithCompletion: ^(FIRAuthDataResult *_Nullable result, NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNil(result); @@ -1609,9 +1609,9 @@ - (void)testSignInAndRetrieveDataWithCustomTokenSuccess { [self expectGetAccountInfo]; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [[FIRAuth auth] signOut:NULL]; - [[FIRAuth auth] signInAndRetrieveDataWithCustomToken:kCustomToken - completion:^(FIRAuthDataResult *_Nullable result, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithCustomToken:kCustomToken + completion:^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUser:result.user]; XCTAssertFalse(result.additionalUserInfo.isNewUser); @@ -1631,9 +1631,9 @@ - (void)testSignInAndRetrieveDataWithCustomTokenFailure { .andDispatchError2([FIRAuthErrorUtils invalidCustomTokenErrorWithMessage:nil]); XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [[FIRAuth auth] signOut:NULL]; - [[FIRAuth auth] signInAndRetrieveDataWithCustomToken:kCustomToken - completion:^(FIRAuthDataResult *_Nullable result, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithCustomToken:kCustomToken + completion:^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNil(result); XCTAssertEqual(error.code, FIRAuthErrorCodeInvalidCustomToken); @@ -1724,10 +1724,10 @@ - (void)testCreateUserAndRetrieveDataWithEmailPasswordSuccess { [self expectGetAccountInfo]; XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [[FIRAuth auth] signOut:NULL]; - [[FIRAuth auth] createUserAndRetrieveDataWithEmail:kEmail - password:kFakePassword - completion:^(FIRAuthDataResult *_Nullable result, - NSError *_Nullable error) { + [[FIRAuth auth] createUserWithEmail:kEmail + password:kFakePassword + completion:^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUser:result.user]; XCTAssertTrue(result.additionalUserInfo.isNewUser); @@ -1749,10 +1749,10 @@ - (void)testCreateUserAndRetrieveDataWithEmailPasswordFailure { .andDispatchError2([FIRAuthErrorUtils weakPasswordErrorWithServerResponseReason:reason]); XCTestExpectation *expectation = [self expectationWithDescription:@"callback"]; [[FIRAuth auth] signOut:NULL]; - [[FIRAuth auth] createUserAndRetrieveDataWithEmail:kEmail - password:kFakePassword - completion:^(FIRAuthDataResult *_Nullable result, - NSError *_Nullable error) { + [[FIRAuth auth] createUserWithEmail:kEmail + password:kFakePassword + completion:^(FIRAuthDataResult *_Nullable result, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNil(result); XCTAssertEqual(error.code, FIRAuthErrorCodeWeakPassword); diff --git a/Example/Auth/Tests/FIRUserTests.m b/Example/Auth/Tests/FIRUserTests.m index e05e9a012df..76a8d544fce 100644 --- a/Example/Auth/Tests/FIRUserTests.m +++ b/Example/Auth/Tests/FIRUserTests.m @@ -1257,7 +1257,8 @@ - (void)testReauthenticateSuccess { }); FIRAuthCredential *emailCredential = [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword]; - [user reauthenticateWithCredential:emailCredential completion:^(NSError *_Nullable error) { + [user reauthenticateWithCredential:emailCredential completion:^(FIRAuthDataResult * _Nullable result, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNil(error); // Verify that the current user is unchanged. @@ -1285,9 +1286,9 @@ - (void)testReauthenticateAndRetrieveDataSuccess { [[FIRAuth auth] signOut:NULL]; FIRAuthCredential *googleCredential = [FIRGoogleAuthProvider credentialWithIDToken:kGoogleIDToken accessToken:kGoogleAccessToken]; - [[FIRAuth auth] signInAndRetrieveDataWithCredential:googleCredential - completion:^(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithCredential:googleCredential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUserGoogle:authResult.user]; XCTAssertEqualObjects(authResult.additionalUserInfo.profile, [[self class] googleProfile]); @@ -1305,10 +1306,9 @@ - (void)testReauthenticateAndRetrieveDataSuccess { FIRAuthCredential *reauthenticateGoogleCredential = [FIRGoogleAuthProvider credentialWithIDToken:kGoogleIDToken accessToken:kGoogleAccessToken]; [authResult.user - reauthenticateAndRetrieveDataWithCredential:reauthenticateGoogleCredential - completion:^(FIRAuthDataResult *_Nullable - reauthenticateAuthResult, - NSError *_Nullable error) { + reauthenticateWithCredential:reauthenticateGoogleCredential + completion:^(FIRAuthDataResult *_Nullable reauthenticateAuthResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNil(error); // Verify that the current user is unchanged. @@ -1373,7 +1373,8 @@ - (void)testReauthenticateFailure { }); FIRAuthCredential *emailCredential = [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword]; - [user reauthenticateWithCredential:emailCredential completion:^(NSError *_Nullable error) { + [user reauthenticateWithCredential:emailCredential completion:^(FIRAuthDataResult * _Nullable result, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); // Verify user mismatch error. XCTAssertEqual(error.code, FIRAuthErrorCodeUserMismatch); @@ -1408,7 +1409,9 @@ - (void)testReauthenticateUserMismatchFailure { }); FIRAuthCredential *googleCredential = [FIRGoogleAuthProvider credentialWithIDToken:kGoogleIDToken accessToken:kGoogleAccessToken]; - [user reauthenticateWithCredential:googleCredential completion:^(NSError *_Nullable error) { + [user reauthenticateWithCredential:googleCredential + completion:^(FIRAuthDataResult * _Nullable result, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); // Verify user mismatch error. XCTAssertEqual(error.code, FIRAuthErrorCodeUserMismatch); @@ -1437,9 +1440,9 @@ - (void)testlinkAndRetrieveDataSuccess { [[FIRAuth auth] signOut:NULL]; FIRAuthCredential *facebookCredential = [FIRFacebookAuthProvider credentialWithAccessToken:kFacebookAccessToken]; - [[FIRAuth auth] signInAndRetrieveDataWithCredential:facebookCredential - completion:^(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithCredential:facebookCredential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUserFacebook:authResult.user]; XCTAssertEqualObjects(authResult.additionalUserInfo.profile, [[self class] googleProfile]); @@ -1456,10 +1459,9 @@ - (void)testlinkAndRetrieveDataSuccess { FIRAuthCredential *linkGoogleCredential = [FIRGoogleAuthProvider credentialWithIDToken:kGoogleIDToken accessToken:kGoogleAccessToken]; - [authResult.user linkAndRetrieveDataWithCredential:linkGoogleCredential - completion:^(FIRAuthDataResult *_Nullable - linkAuthResult, - NSError *_Nullable error) { + [authResult.user linkWithCredential:linkGoogleCredential + completion:^(FIRAuthDataResult *_Nullable linkAuthResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNil(error); // Verify that the current user is unchanged. @@ -1498,9 +1500,9 @@ - (void)testlinkAndRetrieveDataError { [[FIRAuth auth] signOut:NULL]; FIRAuthCredential *facebookCredential = [FIRFacebookAuthProvider credentialWithAccessToken:kFacebookAccessToken]; - [[FIRAuth auth] signInAndRetrieveDataWithCredential:facebookCredential - completion:^(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithCredential:facebookCredential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUserFacebook:authResult.user]; XCTAssertEqualObjects(authResult.additionalUserInfo.profile, [[self class] googleProfile]); @@ -1519,10 +1521,9 @@ - (void)testlinkAndRetrieveDataError { FIRAuthCredential *linkGoogleCredential = [FIRGoogleAuthProvider credentialWithIDToken:kGoogleIDToken accessToken:kGoogleAccessToken]; - [authResult.user linkAndRetrieveDataWithCredential:linkGoogleCredential - completion:^(FIRAuthDataResult *_Nullable - linkAuthResult, - NSError *_Nullable error) { + [authResult.user linkWithCredential:linkGoogleCredential + completion:^(FIRAuthDataResult *_Nullable linkAuthResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNil(linkAuthResult); XCTAssertEqual(error.code, FIRAuthErrorCodeAccountExistsWithDifferentCredential); @@ -1550,9 +1551,9 @@ - (void)testlinkAndRetrieveDataProviderAlreadyLinked { [[FIRAuth auth] signOut:NULL]; FIRAuthCredential *facebookCredential = [FIRFacebookAuthProvider credentialWithAccessToken:kFacebookAccessToken]; - [[FIRAuth auth] signInAndRetrieveDataWithCredential:facebookCredential - completion:^(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithCredential:facebookCredential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUserFacebook:authResult.user]; XCTAssertEqualObjects(authResult.additionalUserInfo.profile, [[self class] googleProfile]); @@ -1562,10 +1563,9 @@ - (void)testlinkAndRetrieveDataProviderAlreadyLinked { FIRAuthCredential *linkFacebookCredential = [FIRFacebookAuthProvider credentialWithAccessToken:kFacebookAccessToken]; - [authResult.user linkAndRetrieveDataWithCredential:linkFacebookCredential - completion:^(FIRAuthDataResult *_Nullable - linkAuthResult, - NSError *_Nullable error) { + [authResult.user linkWithCredential:linkFacebookCredential + completion:^(FIRAuthDataResult *_Nullable linkAuthResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNil(linkAuthResult); XCTAssertEqual(error.code, FIRAuthErrorCodeProviderAlreadyLinked); @@ -1592,9 +1592,9 @@ - (void)testlinkAndRetrieveDataErrorAutoSignOut { [[FIRAuth auth] signOut:NULL]; FIRAuthCredential *facebookCredential = [FIRFacebookAuthProvider credentialWithAccessToken:kFacebookAccessToken]; - [[FIRAuth auth] signInAndRetrieveDataWithCredential:facebookCredential - completion:^(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithCredential:facebookCredential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUserFacebook:authResult.user]; XCTAssertEqualObjects(authResult.additionalUserInfo.profile, [[self class] googleProfile]); @@ -1612,10 +1612,9 @@ - (void)testlinkAndRetrieveDataErrorAutoSignOut { FIRAuthCredential *linkGoogleCredential = [FIRGoogleAuthProvider credentialWithIDToken:kGoogleIDToken accessToken:kGoogleAccessToken]; - [authResult.user linkAndRetrieveDataWithCredential:linkGoogleCredential - completion:^(FIRAuthDataResult *_Nullable - linkAuthResult, - NSError *_Nullable error) { + [authResult.user linkWithCredential:linkGoogleCredential + completion:^(FIRAuthDataResult *_Nullable linkAuthResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNil(linkAuthResult); XCTAssertEqual(error.code, FIRAuthErrorCodeUserDisabled); @@ -1671,9 +1670,9 @@ - (void)testLinkingAnonymousAccountsUpdatesIsAnonymous { }); XCTAssertTrue(user.isAnonymous); - [user linkAndRetrieveDataWithCredential:linkEmailCredential - completion:^(FIRAuthDataResult *_Nullable linkAuthResult, - NSError *_Nullable error) { + [user linkWithCredential:linkEmailCredential + completion:^(FIRAuthDataResult *_Nullable linkAuthResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNil(error); XCTAssertEqualObjects(user.email, kEmail); @@ -1701,9 +1700,9 @@ - (void)testlinkEmailAndRetrieveDataSuccess { [[FIRAuth auth] signOut:NULL]; FIRAuthCredential *facebookCredential = [FIRFacebookAuthProvider credentialWithAccessToken:kFacebookAccessToken]; - [[FIRAuth auth] signInAndRetrieveDataWithCredential:facebookCredential - completion:^(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithCredential:facebookCredential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUserFacebook:authResult.user]; XCTAssertEqualObjects(authResult.additionalUserInfo.profile, [[self class] googleProfile]); @@ -1736,10 +1735,9 @@ - (void)testlinkEmailAndRetrieveDataSuccess { FIRAuthCredential *linkEmailCredential = [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword]; - [authResult.user linkAndRetrieveDataWithCredential:linkEmailCredential - completion:^(FIRAuthDataResult *_Nullable - linkAuthResult, - NSError *_Nullable error) { + [authResult.user linkWithCredential:linkEmailCredential + completion:^(FIRAuthDataResult *_Nullable linkAuthResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNil(error); XCTAssertEqualObjects(linkAuthResult.user.email, kEmail); @@ -1769,9 +1767,9 @@ - (void)testlinkEmailProviderAlreadyLinkedError { [[FIRAuth auth] signOut:NULL]; FIRAuthCredential *facebookCredential = [FIRFacebookAuthProvider credentialWithAccessToken:kFacebookAccessToken]; - [[FIRAuth auth] signInAndRetrieveDataWithCredential:facebookCredential - completion:^(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithCredential:facebookCredential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUserFacebook:authResult.user]; XCTAssertEqualObjects(authResult.additionalUserInfo.profile, [[self class] googleProfile]); @@ -1804,19 +1802,17 @@ - (void)testlinkEmailProviderAlreadyLinkedError { FIRAuthCredential *linkEmailCredential = [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword]; - [authResult.user linkAndRetrieveDataWithCredential:linkEmailCredential - completion:^(FIRAuthDataResult *_Nullable - linkAuthResult, - NSError *_Nullable error) { + [authResult.user linkWithCredential:linkEmailCredential + completion:^(FIRAuthDataResult *_Nullable linkAuthResult, + NSError *_Nullable error) { XCTAssertNil(error); XCTAssertEqualObjects(linkAuthResult.user.email, kEmail); XCTAssertEqualObjects(linkAuthResult.user.displayName, kEmailDisplayName); // Try linking same credential a second time to trigger client side error. - [authResult.user linkAndRetrieveDataWithCredential:linkEmailCredential - completion:^(FIRAuthDataResult *_Nullable - linkAuthResult, - NSError *_Nullable error) { + [authResult.user linkWithCredential:linkEmailCredential + completion:^(FIRAuthDataResult *_Nullable linkAuthResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNil(linkAuthResult); XCTAssertEqual(error.code, FIRAuthErrorCodeProviderAlreadyLinked); @@ -1845,9 +1841,9 @@ - (void)testlinkEmailAndRetrieveDataError { [[FIRAuth auth] signOut:NULL]; FIRAuthCredential *facebookCredential = [FIRFacebookAuthProvider credentialWithAccessToken:kFacebookAccessToken]; - [[FIRAuth auth] signInAndRetrieveDataWithCredential:facebookCredential - completion:^(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithCredential:facebookCredential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUserFacebook:authResult.user]; XCTAssertEqualObjects(authResult.additionalUserInfo.profile, [[self class] googleProfile]); @@ -1866,11 +1862,10 @@ - (void)testlinkEmailAndRetrieveDataError { }); FIRAuthCredential *linkEmailCredential = - [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword]; - [authResult.user linkAndRetrieveDataWithCredential:linkEmailCredential - completion:^(FIRAuthDataResult *_Nullable - linkAuthResult, - NSError *_Nullable error) { + [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword]; + [authResult.user linkWithCredential:linkEmailCredential + completion:^(FIRAuthDataResult *_Nullable linkAuthResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNil(linkAuthResult); XCTAssertEqual(error.code, FIRAuthErrorCodeTooManyRequests); @@ -1898,9 +1893,9 @@ - (void)testlinkEmailAndRetrieveDataErrorAutoSignOut { [[FIRAuth auth] signOut:NULL]; FIRAuthCredential *facebookCredential = [FIRFacebookAuthProvider credentialWithAccessToken:kFacebookAccessToken]; - [[FIRAuth auth] signInAndRetrieveDataWithCredential:facebookCredential - completion:^(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithCredential:facebookCredential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUserFacebook:authResult.user]; XCTAssertEqualObjects(authResult.additionalUserInfo.profile, [[self class] googleProfile]); @@ -1920,10 +1915,9 @@ - (void)testlinkEmailAndRetrieveDataErrorAutoSignOut { FIRAuthCredential *linkEmailCredential = [FIREmailAuthProvider credentialWithEmail:kEmail password:kFakePassword]; - [authResult.user linkAndRetrieveDataWithCredential:linkEmailCredential - completion:^(FIRAuthDataResult *_Nullable - linkAuthResult, - NSError *_Nullable error) { + [authResult.user linkWithCredential:linkEmailCredential + completion:^(FIRAuthDataResult *_Nullable linkAuthResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); XCTAssertNil(linkAuthResult); XCTAssertEqual(error.code, FIRAuthErrorCodeUserTokenExpired); @@ -1951,9 +1945,9 @@ - (void)testlinkCredentialSuccess { [[FIRAuth auth] signOut:NULL]; FIRAuthCredential *facebookCredential = [FIRFacebookAuthProvider credentialWithAccessToken:kFacebookAccessToken]; - [[FIRAuth auth] signInAndRetrieveDataWithCredential:facebookCredential - completion:^(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithCredential:facebookCredential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUserFacebook:authResult.user]; XCTAssertEqualObjects(authResult.additionalUserInfo.profile, [[self class] googleProfile]); @@ -1971,10 +1965,10 @@ - (void)testlinkCredentialSuccess { FIRAuthCredential *linkGoogleCredential = [FIRGoogleAuthProvider credentialWithIDToken:kGoogleIDToken accessToken:kGoogleAccessToken]; [authResult.user linkWithCredential:linkGoogleCredential - completion:^(FIRUser *_Nullable user, + completion:^(FIRAuthDataResult * _Nullable result, NSError *_Nullable error) { XCTAssertNil(error); - id userInfo = user.providerData.firstObject; + id userInfo = result.user.providerData.firstObject; XCTAssertEqual(userInfo.providerID, FIRGoogleAuthProviderID); XCTAssertEqual([FIRAuth auth].currentUser, authResult.user); [expectation fulfill]; @@ -2001,9 +1995,9 @@ - (void)testlinkCredentialError { [[FIRAuth auth] signOut:NULL]; FIRAuthCredential *facebookCredential = [FIRFacebookAuthProvider credentialWithAccessToken:kFacebookAccessToken]; - [[FIRAuth auth] signInAndRetrieveDataWithCredential:facebookCredential - completion:^(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithCredential:facebookCredential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUserFacebook:authResult.user]; XCTAssertEqualObjects(authResult.additionalUserInfo.profile, [[self class] googleProfile]); @@ -2022,9 +2016,9 @@ - (void)testlinkCredentialError { FIRAuthCredential *linkGoogleCredential = [FIRGoogleAuthProvider credentialWithIDToken:kGoogleIDToken accessToken:kGoogleAccessToken]; [authResult.user linkWithCredential:linkGoogleCredential - completion:^(FIRUser *_Nullable user, + completion:^(FIRAuthDataResult * _Nullable result, NSError *_Nullable error) { - XCTAssertNil(user); + XCTAssertNil(result.user); XCTAssertEqual(error.code, FIRAuthErrorCodeUserDisabled); [expectation fulfill]; }]; @@ -2049,9 +2043,9 @@ - (void)testlinkCredentialProviderAlreadyLinkedError { [[FIRAuth auth] signOut:NULL]; FIRAuthCredential *facebookCredential = [FIRFacebookAuthProvider credentialWithAccessToken:kFacebookAccessToken]; - [[FIRAuth auth] signInAndRetrieveDataWithCredential:facebookCredential - completion:^(FIRAuthDataResult *_Nullable authResult, - NSError *_Nullable error) { + [[FIRAuth auth] signInWithCredential:facebookCredential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { XCTAssertTrue([NSThread isMainThread]); [self assertUserFacebook:authResult.user]; XCTAssertEqualObjects(authResult.additionalUserInfo.profile, [[self class] googleProfile]); @@ -2062,9 +2056,9 @@ - (void)testlinkCredentialProviderAlreadyLinkedError { FIRAuthCredential *linkFacebookCredential = [FIRFacebookAuthProvider credentialWithAccessToken:kGoogleAccessToken]; [authResult.user linkWithCredential:linkFacebookCredential - completion:^(FIRUser *_Nullable user, + completion:^(FIRAuthDataResult * _Nullable result, NSError *_Nullable error) { - XCTAssertNil(user); + XCTAssertNil(result.user); XCTAssertEqual(error.code, FIRAuthErrorCodeProviderAlreadyLinked); [expectation fulfill]; }]; @@ -2105,10 +2099,8 @@ - (void)testlinkPhoneAuthCredentialSuccess { FIRPhoneAuthCredential *credential = [[FIRPhoneAuthProvider provider] credentialWithVerificationID:kVerificationID verificationCode:kVerificationCode]; - [user linkAndRetrieveDataWithCredential:credential - completion:^(FIRAuthDataResult *_Nullable - linkAuthResult, - NSError *_Nullable error) { + [user linkWithCredential:credential completion:^(FIRAuthDataResult *_Nullable linkAuthResult, + NSError *_Nullable error) { XCTAssertNil(error); XCTAssertEqualObjects([FIRAuth auth].currentUser.providerData.firstObject.providerID, FIRPhoneAuthProviderID); @@ -2170,10 +2162,8 @@ - (void)testUnlinkPhoneAuthCredentialSuccess { [[FIRPhoneAuthProvider provider] credentialWithVerificationID:kVerificationID verificationCode:kVerificationCode]; // Link phone credential. - [user linkAndRetrieveDataWithCredential:credential - completion:^(FIRAuthDataResult *_Nullable - linkAuthResult, - NSError *_Nullable error) { + [user linkWithCredential:credential completion:^(FIRAuthDataResult *_Nullable linkAuthResult, + NSError *_Nullable error) { XCTAssertNil(error); XCTAssertEqualObjects([FIRAuth auth].currentUser.providerData.firstObject.providerID, FIRPhoneAuthProviderID); @@ -2216,10 +2206,8 @@ - (void)testlinkPhoneAuthCredentialFailure { FIRPhoneAuthCredential *credential = [[FIRPhoneAuthProvider provider] credentialWithVerificationID:kVerificationID verificationCode:kVerificationCode]; - [user linkAndRetrieveDataWithCredential:credential - completion:^(FIRAuthDataResult *_Nullable - linkAuthResult, - NSError *_Nullable error) { + [user linkWithCredential:credential completion:^(FIRAuthDataResult *_Nullable linkAuthResult, + NSError *_Nullable error) { XCTAssertEqual(error.code, FIRAuthErrorCodeProviderAlreadyLinked); [expectation fulfill]; }]; @@ -2274,10 +2262,9 @@ - (void)testlinkPhoneCredentialAlreadyExistsError { FIRPhoneAuthCredential *credential = [[FIRPhoneAuthProvider provider] credentialWithVerificationID:kVerificationID verificationCode:kVerificationCode]; - [user linkAndRetrieveDataWithCredential:credential - completion:^(FIRAuthDataResult *_Nullable - linkAuthResult, - NSError *_Nullable error) { + [user linkWithCredential:credential + completion:^(FIRAuthDataResult *_Nullable linkAuthResult, + NSError *_Nullable error) { XCTAssertNil(linkAuthResult); XCTAssertEqual(error.code, FIRAuthErrorCodeCredentialAlreadyInUse); FIRPhoneAuthCredential *credential = error.userInfo[FIRAuthErrorUserInfoUpdatedCredentialKey]; diff --git a/Firebase/Auth/Source/Auth/FIRAuth.m b/Firebase/Auth/Source/Auth/FIRAuth.m index 00fda365ed7..2ee83cf4abb 100644 --- a/Firebase/Auth/Source/Auth/FIRAuth.m +++ b/Firebase/Auth/Source/Auth/FIRAuth.m @@ -728,10 +728,13 @@ - (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 { diff --git a/Firebase/Auth/Source/User/FIRUser.m b/Firebase/Auth/Source/User/FIRUser.m index b5fd1198226..cae4e123428 100644 --- a/Firebase/Auth/Source/User/FIRUser.m +++ b/Firebase/Auth/Source/User/FIRUser.m @@ -750,10 +750,14 @@ - (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(), ^{ @@ -966,10 +970,13 @@ - (void)internalGetTokenForcingRefresh:(BOOL)forceRefresh }]; } +#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 { From e32aadc413818e2a104168e11d9c343db2de4313 Mon Sep 17 00:00:00 2001 From: Chuan Ren Date: Thu, 4 Apr 2019 14:12:56 -0700 Subject: [PATCH 4/4] Update swift version for auth api tests --- Example/Firebase.xcodeproj/project.pbxproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Example/Firebase.xcodeproj/project.pbxproj b/Example/Firebase.xcodeproj/project.pbxproj index 3f3966a38a6..600bba1096f 100644 --- a/Example/Firebase.xcodeproj/project.pbxproj +++ b/Example/Firebase.xcodeproj/project.pbxproj @@ -3686,7 +3686,7 @@ DE26D25C1F7049F1004AE1D3 = { CreatedOnToolsVersion = 9.0; DevelopmentTeam = EQHXZ8M8AV; - LastSwiftMigration = 1010; + LastSwiftMigration = 1020; ProvisioningStyle = Automatic; TestTargetID = DE26D22D1F70398A004AE1D3; }; @@ -7044,7 +7044,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Auth/ApiTests/Auth_ApiTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Sample.app/Sample"; }; @@ -7079,7 +7079,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.google.Auth-ApiTests"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Auth/ApiTests/Auth_ApiTests-Bridging-Header.h"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Sample.app/Sample"; };