diff --git a/FirebaseAuthUI/AccountManagement/FUIAccountSettingsOperationForgotPassword.m b/FirebaseAuthUI/AccountManagement/FUIAccountSettingsOperationForgotPassword.m index 45891f2c449..4b829b852eb 100644 --- a/FirebaseAuthUI/AccountManagement/FUIAccountSettingsOperationForgotPassword.m +++ b/FirebaseAuthUI/AccountManagement/FUIAccountSettingsOperationForgotPassword.m @@ -65,30 +65,26 @@ - (void)onPasswordRecovery:(NSString *)email { [self.delegate.auth sendPasswordResetWithEmail:email completion:^(NSError *_Nullable error) { - // The dispatch is a workaround for a bug in FirebaseAuth 3.0.2, which doesn't call the - // completion block on the main queue. - dispatch_async(dispatch_get_main_queue(), ^{ - [self.delegate decrementActivity]; + [self.delegate decrementActivity]; - if (error) { - [self finishOperationWithError:error]; - return; - } + if (error) { + [self finishOperationWithError:error]; + return; + } - NSString *message = [NSString stringWithFormat: - FUILocalizedString(kStr_PasswordRecoveryEmailSentMessage), email]; - UIAlertController *alertController = - [UIAlertController alertControllerWithTitle:nil - message:message - preferredStyle:UIAlertControllerStyleAlert]; - UIAlertAction *okAction = [UIAlertAction actionWithTitle:FUILocalizedString(kStr_OK) - style:UIAlertActionStyleDefault - handler:^(UIAlertAction *_Nonnull action) { - [self finishOperationWithError:error]; - }]; - [alertController addAction:okAction]; - [self.delegate presentViewController:alertController]; - }); + NSString *message = [NSString stringWithFormat: + FUILocalizedString(kStr_PasswordRecoveryEmailSentMessage), email]; + UIAlertController *alertController = + [UIAlertController alertControllerWithTitle:nil + message:message + preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction *okAction = [UIAlertAction actionWithTitle:FUILocalizedString(kStr_OK) + style:UIAlertActionStyleDefault + handler:^(UIAlertAction *_Nonnull action) { + [self finishOperationWithError:error]; + }]; + [alertController addAction:okAction]; + [self.delegate presentViewController:alertController]; }]; } diff --git a/FirebaseAuthUI/FUIAuth.h b/FirebaseAuthUI/FUIAuth.h index 52170807dfe..8fa95b3ff2a 100644 --- a/FirebaseAuthUI/FUIAuth.h +++ b/FirebaseAuthUI/FUIAuth.h @@ -42,18 +42,35 @@ typedef void (^FUIAuthResultCallback)(FIRUser *_Nullable user, NSError *_Nullabl */ @protocol FUIAuthDelegate -/** @fn authUI:didSignInWithUser:error: +@optional + +/** @fn authUI:didSignInWithAuthDataResult:error: @brief Message sent after the sign in process has completed to report the signed in user or error encountered. @param authUI The @c FUIAuth instance sending the message. + @param authDataResult The data result if the sign in attempt was successful. + @param error The error that occurred during sign in, if any. + */ +- (void)authUI:(FUIAuth *)authUI + didSignInWithAuthDataResult:(nullable FIRAuthDataResult *)authDataResult + error:(nullable NSError *)error; + +/** @fn authUI:didSignInWithUser:error: + @brief This is deprecated API and will be removed in a future release. + Use @c authUI:didSignInWithAuthDataResult:error: + Both sign in call backs are called (@c authUI:didSignInWithAuthDataResult:error: + and @c authUI:didSignInWithUser:error:). + This message is sent after the sign in process has completed to report the signed in user or + error encountered. + @param authUI The @c FUIAuth instance sending the message. @param user The signed in user if the sign in attempt was successful. @param error The error that occurred during sign in, if any. */ - (void)authUI:(FUIAuth *)authUI didSignInWithUser:(nullable FIRUser *)user - error:(nullable NSError *)error; + error:(nullable NSError *)error +__attribute__((deprecated("Instead use authUI:didSignInWithAuthDataResult:error:"))); -@optional /** @fn authUI:didFinishOperation:error: @brief Message sent after finishing Account Management operation. diff --git a/FirebaseAuthUI/FUIAuth.m b/FirebaseAuthUI/FUIAuth.m index 71d6ff577ee..af789c66ec5 100644 --- a/FirebaseAuthUI/FUIAuth.m +++ b/FirebaseAuthUI/FUIAuth.m @@ -166,7 +166,7 @@ - (void)signInWithProviderUI:(id)providerUI [presentingViewController isKindOfClass:[FUIAuthPickerViewController class]]; if (error) { if (!isAuthPickerShown || error.code != FUIAuthErrorCodeUserCancelledSignIn) { - [self invokeResultCallbackWithUser:nil error:error]; + [self invokeResultCallbackWithAuthDataResult:nil error:error]; } if (result) { result(nil, error); @@ -174,8 +174,9 @@ - (void)signInWithProviderUI:(id)providerUI return; } - [self.auth signInWithCredential:credential - completion:^(FIRUser *_Nullable user, NSError *_Nullable error) { + [self.auth signInAndRetrieveDataWithCredential:credential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { if (error && error.code == FIRAuthErrorCodeAccountExistsWithDifferentCredential) { NSString *email = error.userInfo[kErrorUserInfoEmailKey]; [self handleAccountLinkingForEmail:email @@ -185,20 +186,22 @@ - (void)signInWithProviderUI:(id)providerUI return; } - if (result) { - result(user, error); - } - if (error) { - [self invokeResultCallbackWithUser:user error:error]; + if (result) { + result(nil, error); + } + [self invokeResultCallbackWithAuthDataResult:nil error:error]; } else { + if (result) { + result(authResult.user, nil); + } // Hide Auth Picker Controller which was presented modally. if (isAuthPickerShown && presentingViewController.presentingViewController) { [presentingViewController dismissViewControllerAnimated:YES completion:^{ - [self invokeResultCallbackWithUser:user error:error]; + [self invokeResultCallbackWithAuthDataResult:authResult error:nil]; }]; } else { - [self invokeResultCallbackWithUser:user error:error]; + [self invokeResultCallbackWithAuthDataResult:authResult error:nil]; } } }]; @@ -224,7 +227,7 @@ - (void)handleAccountLinkingForEmail:(NSString *)email presentingViewController:presentingViewController]; } else { [presentingViewController dismissViewControllerAnimated:YES completion:^{ - [self invokeResultCallbackWithUser:nil error:error]; + [self invokeResultCallbackWithAuthDataResult:nil error:error]; }]; } return; @@ -287,29 +290,30 @@ - (void)handleAccountLinkingForEmail:(NSString *)email } return; } - [self invokeResultCallbackWithUser:nil error:error]; + [self invokeResultCallbackWithAuthDataResult:nil error:error]; return; } [self.auth signInWithCredential:credential completion:^(FIRUser *_Nullable user, NSError *_Nullable error) { if (error) { - [self invokeResultCallbackWithUser:nil error:error]; + [self invokeResultCallbackWithAuthDataResult:nil error:error]; if (result) { result(nil, error); } return; } - [user linkWithCredential:newCredential completion:^(FIRUser *_Nullable user, - NSError *_Nullable error) { + [user linkAndRetrieveDataWithCredential:newCredential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { if (result) { - result(user, error); + result(authResult.user, error); } // Ignore any error (most likely caused by email mismatch) and treat the user as // successfully signed in. [presentingViewController dismissViewControllerAnimated:YES completion:^{ - [self invokeResultCallbackWithUser:user error:nil]; + [self invokeResultCallbackWithAuthDataResult:authResult error:nil]; }]; }]; }]; @@ -322,9 +326,15 @@ - (void)handleAccountLinkingForEmail:(NSString *)email #pragma mark - Internal Methods -- (void)invokeResultCallbackWithUser:(FIRUser *_Nullable)user error:(NSError *_Nullable)error { +- (void)invokeResultCallbackWithAuthDataResult:(nullable FIRAuthDataResult *)authDataResult + error:(nullable NSError *)error { dispatch_async(dispatch_get_main_queue(), ^{ - [self.delegate authUI:self didSignInWithUser:user error:error]; + if ([self.delegate respondsToSelector:@selector(authUI:didSignInWithAuthDataResult:error:)]) { + [self.delegate authUI:self didSignInWithAuthDataResult:authDataResult error:error]; + } + if ([self.delegate respondsToSelector:@selector(authUI:didSignInWithUser:error:)]) { + [self.delegate authUI:self didSignInWithUser:authDataResult.user error:error]; + } }); } diff --git a/FirebaseAuthUI/FUIAuthBaseViewController.m b/FirebaseAuthUI/FUIAuthBaseViewController.m index 898124cc541..b1ab3dfac5c 100644 --- a/FirebaseAuthUI/FUIAuthBaseViewController.m +++ b/FirebaseAuthUI/FUIAuthBaseViewController.m @@ -337,7 +337,7 @@ - (void)decrementActivity { - (void)cancelAuthorization { [self.navigationController dismissViewControllerAnimated:YES completion:^{ NSError *error = [FUIAuthErrorUtils userCancelledSignInError]; - [self.authUI invokeResultCallbackWithUser:nil error:error]; + [self.authUI invokeResultCallbackWithAuthDataResult:nil error:error]; }]; } diff --git a/FirebaseAuthUI/FUIAuth_Internal.h b/FirebaseAuthUI/FUIAuth_Internal.h index 0bb5c3271c4..ac0e354021f 100644 --- a/FirebaseAuthUI/FUIAuth_Internal.h +++ b/FirebaseAuthUI/FUIAuth_Internal.h @@ -20,12 +20,13 @@ NS_ASSUME_NONNULL_BEGIN @interface FUIAuth () -/** @fn invokeResultCallbackWithUser:error: +/** @fn invokeResultCallbackWithAuthDataResult:error: @brief Invokes the auth UI result callback. - @param user The user signed in, if any. + @param authDataResult The sign in data result, if any. @param error The error which occurred, if any. */ -- (void)invokeResultCallbackWithUser:(FIRUser *_Nullable)user error:(NSError *_Nullable)error; +- (void)invokeResultCallbackWithAuthDataResult:(nullable FIRAuthDataResult *)authDataResult + error:(nullable NSError *)error; /** @fn invokeOperationCallback:error: @brief Invokes the auth UI operation callback. @@ -43,8 +44,8 @@ NS_ASSUME_NONNULL_BEGIN - (nullable id)providerWithID:(NSString *)providerID; /** @fn signInWithProviderUI:presentingViewController:defaultValue: - @brief Signs in with specified provider. @see FUIAuthDelegate.authUI:didSignInWithUser:error: - for method callback. + @brief Signs in with specified provider. + @see FUIAuthDelegate.authUI:didSignInWithAuthDataResult:error: for method callback. @param providerUI The authentication provider used for signing in. @param presentingViewController The view controller used to present the UI. @param defaultValue The provider default initialization value (e g email or phone number) diff --git a/FirebaseAuthUI/FUIEmailEntryViewController.m b/FirebaseAuthUI/FUIEmailEntryViewController.m index ebd15646d0c..29205f9825a 100644 --- a/FirebaseAuthUI/FUIEmailEntryViewController.m +++ b/FirebaseAuthUI/FUIEmailEntryViewController.m @@ -139,7 +139,7 @@ - (void)onNext:(NSString *)emailText { [self showAlertWithMessage:FUILocalizedString(kStr_InvalidEmailError)]; } else { [self.navigationController dismissViewControllerAnimated:YES completion:^{ - [self.authUI invokeResultCallbackWithUser:nil error:error]; + [self.authUI invokeResultCallbackWithAuthDataResult:nil error:error]; }]; } return; @@ -261,10 +261,10 @@ - (void)signInWithProvider:(id)provider email:(NSString *)email // Sign out first to make sure sign in starts with a clean state. [provider signOut]; [provider signInWithDefaultValue:email - presentingViewController:self - completion:^(FIRAuthCredential *_Nullable credential, - NSError *_Nullable error, - _Nullable FIRAuthResultCallback result) { + presentingViewController:self + completion:^(FIRAuthCredential *_Nullable credential, + NSError *_Nullable error, + _Nullable FIRAuthResultCallback result) { if (error) { [self decrementActivity]; if (result) { @@ -272,23 +272,24 @@ - (void)signInWithProvider:(id)provider email:(NSString *)email } [self.navigationController dismissViewControllerAnimated:YES completion:^{ - [self.authUI invokeResultCallbackWithUser:nil error:error]; + [self.authUI invokeResultCallbackWithAuthDataResult:nil error:error]; }]; return; } - [self.auth signInWithCredential:credential - completion:^(FIRUser *_Nullable user, NSError *_Nullable error) { + [self.auth signInAndRetrieveDataWithCredential:credential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { [self decrementActivity]; if (result) { - result(user, error); + result(authResult.user, error); } if (error) { - [self.authUI invokeResultCallbackWithUser:nil error:error]; + [self.authUI invokeResultCallbackWithAuthDataResult:nil error:error]; } else { [self.navigationController dismissViewControllerAnimated:YES completion:^{ - [self.authUI invokeResultCallbackWithUser:user error:error]; + [self.authUI invokeResultCallbackWithAuthDataResult:authResult error:error]; }]; } }]; diff --git a/FirebaseAuthUI/FUIPasswordRecoveryViewController.m b/FirebaseAuthUI/FUIPasswordRecoveryViewController.m index 719c7f24569..b3001d48e0d 100644 --- a/FirebaseAuthUI/FUIPasswordRecoveryViewController.m +++ b/FirebaseAuthUI/FUIPasswordRecoveryViewController.m @@ -121,28 +121,24 @@ - (void)recoverEmail:(NSString *)email { [self.auth sendPasswordResetWithEmail:email completion:^(NSError *_Nullable error) { - // The dispatch is a workaround for a bug in FirebaseAuth 3.0.2, which doesn't call the - // completion block on the main queue. - dispatch_async(dispatch_get_main_queue(), ^{ - [self decrementActivity]; - - if (error) { - if (error.code == FIRAuthErrorCodeUserNotFound) { - [self showAlertWithMessage:FUILocalizedString(kStr_UserNotFoundError)]; - return; - } - - [self.navigationController dismissViewControllerAnimated:YES completion:^{ - [self.authUI invokeResultCallbackWithUser:nil error:error]; - }]; - return; - } - - NSString *message = - [NSString stringWithFormat:FUILocalizedString(kStr_PasswordRecoveryEmailSentMessage), email]; - [self showAlertWithMessage:message]; - }); - }]; + [self decrementActivity]; + + if (error) { + if (error.code == FIRAuthErrorCodeUserNotFound) { + [self showAlertWithMessage:FUILocalizedString(kStr_UserNotFoundError)]; + return; + } + + [self.navigationController dismissViewControllerAnimated:YES completion:^{ + [self.authUI invokeResultCallbackWithAuthDataResult:nil error:error]; + }]; + return; + } + + NSString *message = [NSString stringWithFormat: + FUILocalizedString(kStr_PasswordRecoveryEmailSentMessage), email]; + [self showAlertWithMessage:message]; + }]; } - (void)textFieldDidChange { diff --git a/FirebaseAuthUI/FUIPasswordSignInViewController.m b/FirebaseAuthUI/FUIPasswordSignInViewController.m index e553f4eb174..162254b7156 100644 --- a/FirebaseAuthUI/FUIPasswordSignInViewController.m +++ b/FirebaseAuthUI/FUIPasswordSignInViewController.m @@ -109,32 +109,34 @@ - (void)signInWithDefaultValue:(NSString *)email andPassword:(NSString *)passwor [self incrementActivity]; - [self.auth signInWithEmail:email - password:password - completion:^(FIRUser *_Nullable user, NSError *_Nullable error) { - [self decrementActivity]; - - if (error) { - switch (error.code) { - case FIRAuthErrorCodeWrongPassword: - [self showAlertWithMessage:FUILocalizedString(kStr_WrongPasswordError)]; - return; - case FIRAuthErrorCodeUserNotFound: - [self showAlertWithMessage:FUILocalizedString(kStr_UserNotFoundError)]; - return; - case FIRAuthErrorCodeUserDisabled: - [self showAlertWithMessage:FUILocalizedString(kStr_AccountDisabledError)]; - return; - case FIRAuthErrorCodeTooManyRequests: - [self showAlertWithMessage:FUILocalizedString(kStr_SignInTooManyTimesError)]; - return; - } - } - - [self.navigationController dismissViewControllerAnimated:YES completion:^{ - [self.authUI invokeResultCallbackWithUser:user error:error]; - }]; - }]; + FIRAuthCredential *credential = + [FIREmailAuthProvider credentialWithEmail:email password:password]; + [self.auth signInAndRetrieveDataWithCredential:credential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { + [self decrementActivity]; + + if (error) { + switch (error.code) { + case FIRAuthErrorCodeWrongPassword: + [self showAlertWithMessage:FUILocalizedString(kStr_WrongPasswordError)]; + return; + case FIRAuthErrorCodeUserNotFound: + [self showAlertWithMessage:FUILocalizedString(kStr_UserNotFoundError)]; + return; + case FIRAuthErrorCodeUserDisabled: + [self showAlertWithMessage:FUILocalizedString(kStr_AccountDisabledError)]; + return; + case FIRAuthErrorCodeTooManyRequests: + [self showAlertWithMessage:FUILocalizedString(kStr_SignInTooManyTimesError)]; + return; + } + } + + [self.navigationController dismissViewControllerAnimated:YES completion:^{ + [self.authUI invokeResultCallbackWithAuthDataResult:authResult error:error]; + }]; + }]; } - (void)signIn { diff --git a/FirebaseAuthUI/FUIPasswordSignUpViewController.m b/FirebaseAuthUI/FUIPasswordSignUpViewController.m index 15658fd7370..f2858dd0809 100644 --- a/FirebaseAuthUI/FUIPasswordSignUpViewController.m +++ b/FirebaseAuthUI/FUIPasswordSignUpViewController.m @@ -180,31 +180,33 @@ - (void)signUpWithEmail:(NSString *)email [self incrementActivity]; - [self.auth createUserWithEmail:email - password:password - completion:^(FIRUser *_Nullable user, NSError *_Nullable error) { + [self.auth createUserAndRetrieveDataWithEmail:email + password:password + completion:^(FIRAuthDataResult *_Nullable authDataResult, + NSError *_Nullable error) { if (error) { [self decrementActivity]; - [self finishSignUpWithUser:nil error:error]; + [self finishSignUpWithAuthDataResult:nil error:error]; return; } - FIRUserProfileChangeRequest *request = [user profileChangeRequest]; + FIRUserProfileChangeRequest *request = [authDataResult.user profileChangeRequest]; request.displayName = username; [request commitChangesWithCompletion:^(NSError *_Nullable error) { [self decrementActivity]; if (error) { - [self finishSignUpWithUser:nil error:error]; + [self finishSignUpWithAuthDataResult:nil error:error]; return; } - [self finishSignUpWithUser:user error:nil]; + [self finishSignUpWithAuthDataResult:authDataResult error:nil]; }]; }]; } -- (void)finishSignUpWithUser:(FIRUser *)user error:(NSError *)error { +- (void)finishSignUpWithAuthDataResult:(nullable FIRAuthDataResult *)authDataResult + error:(nullable NSError *)error { if (error) { switch (error.code) { case FIRAuthErrorCodeEmailAlreadyInUse: @@ -223,7 +225,7 @@ - (void)finishSignUpWithUser:(FIRUser *)user error:(NSError *)error { } [self.navigationController dismissViewControllerAnimated:YES completion:^() { - [self.authUI invokeResultCallbackWithUser:user error:error]; + [self.authUI invokeResultCallbackWithAuthDataResult:authDataResult error:error]; }]; } diff --git a/FirebaseAuthUI/FUIPasswordVerificationViewController.m b/FirebaseAuthUI/FUIPasswordVerificationViewController.m index 39332ade63a..da19cf087d7 100644 --- a/FirebaseAuthUI/FUIPasswordVerificationViewController.m +++ b/FirebaseAuthUI/FUIPasswordVerificationViewController.m @@ -140,26 +140,29 @@ - (void)verifyPassword:(NSString *)password { [self incrementActivity]; - [self.auth signInWithEmail:_email - password:password - completion:^(FIRUser *_Nullable user, NSError *_Nullable error) { - if (error) { - [self decrementActivity]; - - [self showAlertWithMessage:FUILocalizedString(kStr_WrongPasswordError)]; - return; - } - - [user linkWithCredential:_newCredential completion:^(FIRUser *_Nullable user, - NSError *_Nullable error) { - [self decrementActivity]; - - // Ignore any error (shouldn't happen) and treat the user as successfully signed in. - [self.navigationController dismissViewControllerAnimated:YES completion:^{ - [self.authUI invokeResultCallbackWithUser:user error:nil]; - }]; - }]; - }]; + FIRAuthCredential *credential = + [FIREmailAuthProvider credentialWithEmail:_email password:password]; + [self.auth signInAndRetrieveDataWithCredential:credential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { + if (error) { + [self decrementActivity]; + + [self showAlertWithMessage:FUILocalizedString(kStr_WrongPasswordError)]; + return; + } + + [authResult.user linkAndRetrieveDataWithCredential:_newCredential + completion:^(FIRAuthDataResult *_Nullable authResult, + NSError *_Nullable error) { + [self decrementActivity]; + + // Ignore any error (shouldn't happen) and treat the user as successfully signed in. + [self.navigationController dismissViewControllerAnimated:YES completion:^{ + [self.authUI invokeResultCallbackWithAuthDataResult:authResult error:nil]; + }]; + }]; + }]; } - (IBAction)forgotPassword { diff --git a/FirebasePhoneAuthUI/FUIPhoneAuth.h b/FirebasePhoneAuthUI/FUIPhoneAuth.h index 434d7ea7086..f277b675eb8 100644 --- a/FirebasePhoneAuthUI/FUIPhoneAuth.h +++ b/FirebasePhoneAuthUI/FUIPhoneAuth.h @@ -34,8 +34,8 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithAuthUI:(FUIAuth *)authUI NS_DESIGNATED_INITIALIZER; /** @fn signInWithPresentingViewController: - @brief Signs in with phone auth provider. @see FUIAuthDelegate.authUI:didSignInWithUser:error: - for method callback. + @brief Signs in with phone auth provider. + @see FUIAuthDelegate.authUI:didSignInWithAuthDataResult:error: for method callback. @param presentingViewController The view controller used to present the UI. */ - (void)signInWithPresentingViewController:(UIViewController *)presentingViewController @@ -43,8 +43,8 @@ __attribute__((deprecated("This is deprecated API and will be removed in a futur "Please use signInWithPresentingViewController:phoneNumber:"))); /** @fn signInWithPresentingViewController:phoneNumber: - @brief Signs in with phone auth provider. @see FUIAuthDelegate.authUI:didSignInWithUser:error: - for method callback. + @brief Signs in with phone auth provider. + @see FUIAuthDelegate.authUI:didSignInWithAuthDataResult:error: for method callback. @param presentingViewController The view controller used to present the UI. @param phoneNumber The default phone number specified in the international format e.g. +14151112233 diff --git a/FirebaseUISample/FUIViewController.m b/FirebaseUISample/FUIViewController.m index 268649956d0..b22204eeb55 100644 --- a/FirebaseUISample/FUIViewController.m +++ b/FirebaseUISample/FUIViewController.m @@ -91,7 +91,7 @@ - (IBAction)onAuthorization:(id)sender { [self.authUIMock isSignInWithEmailHidden]; if (shouldSkipPhoneAuthPicker) { FUIPhoneAuth *provider = _authProviders.firstObject; - [provider signInWithPresentingViewController:self]; + [provider signInWithPresentingViewController:self phoneNumber:nil]; } else { UIViewController *controller = [self.authUIMock authViewController]; [self presentViewController:controller animated:YES completion:nil]; @@ -161,7 +161,9 @@ - (void)deselectAllCellsExcept:(NSIndexPath *)indexPath { #pragma mark - FUIAuthDelegate methods -- (void)authUI:(FUIAuth *)authUI didSignInWithUser:(nullable FIRUser *)user error:(nullable NSError *)error { +- (void)authUI:(FUIAuth *)authUI + didSignInWithAuthDataResult:(nullable FIRAuthDataResult *)authDataResult + error:(nullable NSError *)error { if (error) { if (error.code == FUIAuthErrorCodeUserCancelledSignIn) { [self showAlert:@"User cancelled sign-in"]; @@ -173,20 +175,21 @@ - (void)authUI:(FUIAuth *)authUI didSignInWithUser:(nullable FIRUser *)user erro [self showAlert:detailedError.localizedDescription]; } } else { - _labelUserEmail.text = user.email; + _labelUserEmail.text = authDataResult.user.email; [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:kSectionsSignedInAs] withRowAnimation:UITableViewRowAnimationNone]; } } - (void)showAlert:(NSString *)message { - UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Error" - message:message - preferredStyle:UIAlertControllerStyleAlert]; - UIAlertAction* closeButton = [UIAlertAction - actionWithTitle:@"Close" - style:UIAlertActionStyleDefault - handler:nil]; + UIAlertController *alert = + [UIAlertController alertControllerWithTitle:@"Error" + message:message + preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction* closeButton = + [UIAlertAction actionWithTitle:@"Close" + style:UIAlertActionStyleDefault + handler:nil]; [alert addAction:closeButton]; [self presentViewController:alert animated:YES completion:nil]; @@ -231,48 +234,57 @@ - (void)prepareAuthUIMocks { } - (void)prepareStubsForSimulationExistingUser { - OCMStub([self.authMock fetchProvidersForEmail:OCMOCK_ANY completion:OCMOCK_ANY]).andDo(^(NSInvocation *invocation) { + OCMStub([self.authMock fetchProvidersForEmail:OCMOCK_ANY completion:OCMOCK_ANY]). + andDo(^(NSInvocation *invocation) { FIRProviderQueryCallback mockedCallback; [invocation getArgument:&mockedCallback atIndex:3]; mockedCallback(@[@"password"], nil); }); - [self mockSignInWithEmail]; + [self mockSignInWithCredential]; } - (void)prepareStubsForSimulationNewUser { - OCMStub([self.authMock fetchProvidersForEmail:OCMOCK_ANY completion:OCMOCK_ANY]).andDo(^(NSInvocation *invocation) { + OCMStub([self.authMock fetchProvidersForEmail:OCMOCK_ANY completion:OCMOCK_ANY]). + andDo(^(NSInvocation *invocation) { FIRProviderQueryCallback mockedResponse; [invocation getArgument:&mockedResponse atIndex:3]; mockedResponse(nil, nil); }); - OCMStub([self.authMock createUserWithEmail:OCMOCK_ANY password:OCMOCK_ANY completion:OCMOCK_ANY]).andDo(^(NSInvocation *invocation) { - FIRAuthResultCallback mockedCallback; + OCMStub([self.authMock createUserAndRetrieveDataWithEmail:OCMOCK_ANY + password:OCMOCK_ANY + completion:OCMOCK_ANY]). + andDo(^(NSInvocation *invocation) { + FIRAuthDataResultCallback mockedCallback; [invocation getArgument:&mockedCallback atIndex:4]; NSString *responseEmail; [invocation getArgument:&responseEmail atIndex:2]; + id mockDataResult = OCMClassMock([FIRAuthDataResult class]); id mockUser = OCMClassMock([FIRUser class]); OCMStub([mockUser email]).andReturn(responseEmail); + OCMStub([mockDataResult user]).andReturn(mockUser); [self mockUpdateUserRequest:mockUser]; - mockedCallback(mockUser, nil); + mockedCallback(mockDataResult, nil); }); } - (void)prepareStubsForEmailRecovery { - OCMStub([self.authMock fetchProvidersForEmail:OCMOCK_ANY completion:OCMOCK_ANY]).andDo(^(NSInvocation *invocation) { + OCMStub([self.authMock fetchProvidersForEmail:OCMOCK_ANY completion:OCMOCK_ANY]). + andDo(^(NSInvocation *invocation) { FIRProviderQueryCallback mockedCallback; [invocation getArgument:&mockedCallback atIndex:3]; mockedCallback(@[@"password"], nil); }); - OCMStub([self.authMock sendPasswordResetWithEmail:OCMOCK_ANY completion:OCMOCK_ANY]).andDo(^(NSInvocation *invocation) { + OCMStub([self.authMock sendPasswordResetWithEmail:OCMOCK_ANY completion:OCMOCK_ANY]). + andDo(^(NSInvocation *invocation) { FIRSendPasswordResetCallback mockedCallback; [invocation getArgument:&mockedCallback atIndex:3]; mockedCallback(nil); @@ -442,29 +454,13 @@ - (void)mockUpdateUserRequest:(id)mockUser { }); } -- (void)mockSignInWithEmail { - OCMStub([self.authMock signInWithEmail:OCMOCK_ANY password:OCMOCK_ANY completion:OCMOCK_ANY]). - andDo(^(NSInvocation *invocation) { - FIRAuthResultCallback mockedResponse; - [invocation getArgument:&mockedResponse atIndex:4]; - - NSString *responseEmail; - [invocation getArgument:&responseEmail atIndex:2]; - - id mockUser = OCMClassMock([FIRUser class]); - OCMStub([mockUser email]).andReturn(responseEmail); - - mockedResponse(mockUser, nil); - }); -} - - (void)mockSignInWithCredential { - OCMStub([self.authMock signInWithCredential:OCMOCK_ANY completion:OCMOCK_ANY]). + OCMStub([self.authMock signInAndRetrieveDataWithCredential:OCMOCK_ANY completion:OCMOCK_ANY]). andDo(^(NSInvocation *invocation) { - FIRAuthResultCallback mockedResponse; + FIRAuthDataResultCallback mockedResponse; [invocation getArgument:&mockedResponse atIndex:3]; - id mockUser = OCMClassMock([FIRUser class]); - mockedResponse(mockUser, nil); + id mockDataResult = OCMClassMock([FIRAuthDataResult class]); + mockedResponse(mockDataResult, nil); }); } - (void)mockUpdatePasswordRequest:(id)mockUser { @@ -514,9 +510,9 @@ - (void)mockSignInWithProvider:(NSString *)providerId user:(id)mockUser { mockedCallBack(nil); }); - OCMStub([mockProviderUI signInWithEmail:OCMOCK_ANY - presentingViewController:OCMOCK_ANY - completion:OCMOCK_ANY]). + OCMStub([mockProviderUI signInWithDefaultValue:OCMOCK_ANY + presentingViewController:OCMOCK_ANY + completion:OCMOCK_ANY]). andDo(^(NSInvocation *invocation) { FIRAuthProviderSignInCompletionBlock mockedResponse; [invocation getArgument:&mockedResponse atIndex:4]; @@ -545,8 +541,8 @@ - (void)mockServerOperations { // Mock udpate email operation [self mockUpdateEmail:mockUser]; - // mock re-authentication with email - [self mockSignInWithEmail]; + // mock re-authentication with credential + [self mockSignInWithCredential]; // mock update password [self mockUpdatePasswordRequest:mockUser]; diff --git a/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUIAuthViewController.m b/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUIAuthViewController.m index 4af13a5c929..5ebe118f7a8 100644 --- a/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUIAuthViewController.m +++ b/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUIAuthViewController.m @@ -217,7 +217,9 @@ - (IBAction)onAuthorization:(id)sender { #pragma mark - FUIAuthDelegate methods // this method is called only when FUIAuthViewController is delgate of AuthUI -- (void)authUI:(FUIAuth *)authUI didSignInWithUser:(nullable FIRUser *)user error:(nullable NSError *)error { +- (void)authUI:(FUIAuth *)authUI + didSignInWithAuthDataResult:(nullable FIRAuthDataResult *)authDataResult + error:(nullable NSError *)error { if (error) { if (error.code == FUIAuthErrorCodeUserCancelledSignIn) { [self showAlert:@"User cancelled sign-in"]; diff --git a/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUICustomAuthDelegate.m b/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUICustomAuthDelegate.m index d5ab113be0a..6778431d790 100644 --- a/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUICustomAuthDelegate.m +++ b/samples/objc/FirebaseUI-demo-objc/Samples/Auth/FUICustomAuthDelegate.m @@ -26,7 +26,9 @@ @implementation FUICustomAuthDelegate -- (void)authUI:(FUIAuth *)authUI didSignInWithUser:(nullable FIRUser *)user error:(nullable NSError *)error { +- (void)authUI:(FUIAuth *)authUI + didSignInWithAuthDataResult:(nullable FIRAuthDataResult *)authDataResult + error:(nullable NSError *)error { if (error) { if (error.code == FUIAuthErrorCodeUserCancelledSignIn) { NSLog(@"User cancelled sign-in"); @@ -41,53 +43,57 @@ - (void)authUI:(FUIAuth *)authUI didSignInWithUser:(nullable FIRUser *)user erro } - (FUIAuthPickerViewController *)authPickerViewControllerForAuthUI:(FUIAuth *)authUI { - return [[FUICustomAuthPickerViewController alloc] initWithNibName:@"FUICustomAuthPickerViewController" - bundle:[NSBundle mainBundle] - authUI:authUI]; + return [[FUICustomAuthPickerViewController alloc] + initWithNibName:@"FUICustomAuthPickerViewController" + bundle:[NSBundle mainBundle] + authUI:authUI]; } - (FUIEmailEntryViewController *)emailEntryViewControllerForAuthUI:(FUIAuth *)authUI { - return [[FUICustomEmailEntryViewController alloc] initWithNibName:@"FUICustomEmailEntryViewController" - bundle:[NSBundle mainBundle] - authUI:authUI]; - + return [[FUICustomEmailEntryViewController alloc] + initWithNibName:@"FUICustomEmailEntryViewController" + bundle:[NSBundle mainBundle] + authUI:authUI]; } - (FUIPasswordSignInViewController *)passwordSignInViewControllerForAuthUI:(FUIAuth *)authUI email:(NSString *)email { - return [[FUICustomPasswordSignInViewController alloc] initWithNibName:@"FUICustomPasswordSignInViewController" - bundle:[NSBundle mainBundle] - authUI:authUI - email:email]; - + return [[FUICustomPasswordSignInViewController alloc] + initWithNibName:@"FUICustomPasswordSignInViewController" + bundle:[NSBundle mainBundle] + authUI:authUI + email:email]; } - (FUIPasswordSignUpViewController *)passwordSignUpViewControllerForAuthUI:(FUIAuth *)authUI email:(NSString *)email { - return [[FUICustomPasswordSignUpViewController alloc] initWithNibName:@"FUICustomPasswordSignUpViewController" - bundle:[NSBundle mainBundle] - authUI:authUI - email:email]; - + return [[FUICustomPasswordSignUpViewController alloc] + initWithNibName:@"FUICustomPasswordSignUpViewController" + bundle:[NSBundle mainBundle] + authUI:authUI + email:email]; } -- (FUIPasswordRecoveryViewController *)passwordRecoveryViewControllerForAuthUI:(FUIAuth *)authUI - email:(NSString *)email { - return [[FUICustomPasswordRecoveryViewController alloc] initWithNibName:@"FUICustomPasswordRecoveryViewController" - bundle:[NSBundle mainBundle] - authUI:authUI - email:email]; - +- (FUIPasswordRecoveryViewController *) + passwordRecoveryViewControllerForAuthUI:(FUIAuth *)authUI + email:(NSString *)email { + return [[FUICustomPasswordRecoveryViewController alloc] + initWithNibName:@"FUICustomPasswordRecoveryViewController" + bundle:[NSBundle mainBundle] + authUI:authUI + email:email]; } -- (FUIPasswordVerificationViewController *)passwordVerificationViewControllerForAuthUI:(FUIAuth *)authUI - email:(NSString *)email - newCredential:(FIRAuthCredential *)newCredential { - return [[FUICustomPasswordVerificationViewController alloc] initWithNibName:@"FUICustomPasswordVerificationViewController" - bundle:[NSBundle mainBundle] - authUI:authUI - email:email - newCredential:newCredential]; +- (FUIPasswordVerificationViewController *) + passwordVerificationViewControllerForAuthUI:(FUIAuth *)authUI + email:(NSString *)email + newCredential:(FIRAuthCredential *)newCredential { + return [[FUICustomPasswordVerificationViewController alloc] + initWithNibName:@"FUICustomPasswordVerificationViewController" + bundle:[NSBundle mainBundle] + authUI:authUI + email:email + newCredential:newCredential]; } @end diff --git a/samples/swift/FirebaseUI-demo-swift/Samples/Auth/FUICustomAuthUIDelegate.swift b/samples/swift/FirebaseUI-demo-swift/Samples/Auth/FUICustomAuthUIDelegate.swift index 08dc005c5b5..fb2eb3b0541 100644 --- a/samples/swift/FirebaseUI-demo-swift/Samples/Auth/FUICustomAuthUIDelegate.swift +++ b/samples/swift/FirebaseUI-demo-swift/Samples/Auth/FUICustomAuthUIDelegate.swift @@ -20,7 +20,7 @@ import FirebaseAuth class FUICustomAuthDelegate: NSObject, FUIAuthDelegate { - func authUI(_ authUI: FUIAuth, didSignInWith user: User?, error: Error?) { + func authUI(_ authUI: FUIAuth, didSignInWith authDataResult: AuthDataResult?, error: Error?) { switch error { case .some(let error as NSError) where UInt(error.code) == FUIAuthErrorCode.userCancelledSignIn.rawValue: print("User cancelled sign-in")