Skip to content

Commit 9eedcfe

Browse files
Refactor FUIAuth to split out email auth.
2 parents b289e5e + f908ee7 commit 9eedcfe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1424
-507
lines changed

FirebaseAuthUI/FUIAuth.h

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ typedef void (^FUIAuthResultCallback)(FIRUser *_Nullable user, NSError *_Nullabl
4545

4646
@optional
4747

48+
/** @fn authUI:didSignInWithAuthDataResult:error:
49+
@brief Message sent after the sign in process has completed to report the signed in user or
50+
error encountered.
51+
@param authUI The @c FUIAuth instance sending the message.
52+
@param authDataResult The data result if the sign in attempt was successful.
53+
@param url pass the deep link associated with an email link sign-in completion. It is useful
54+
for the developer to access the state before the sign-in attempt was triggered.
55+
@param error The error that occurred during sign in, if any.
56+
*/
57+
- (void)authUI:(FUIAuth *)authUI
58+
didSignInWithAuthDataResult:(nullable FIRAuthDataResult *)authDataResult
59+
URL:(nullable NSURL *)url
60+
error:(nullable NSError *)error;
61+
4862
/** @fn authUI:didSignInWithAuthDataResult:error:
4963
@brief Message sent after the sign in process has completed to report the signed in user or
5064
error encountered.
@@ -171,16 +185,6 @@ __attribute__((deprecated("Instead use authUI:didSignInWithAuthDataResult:error:
171185
*/
172186
@property(nonatomic, copy) NSArray<id<FUIAuthProvider>> *providers;
173187

174-
/** @property signInWithEmailHidden
175-
@brief Whether to hide the "Sign in with email" option, defaults to NO.
176-
*/
177-
@property(nonatomic, assign, getter=isSignInWithEmailHidden) BOOL signInWithEmailHidden;
178-
179-
/** @property allowNewEmailAccounts
180-
@brief Whether to allow new user sign, defaults to YES.
181-
*/
182-
@property(nonatomic, assign) BOOL allowNewEmailAccounts;
183-
184188
/** @property shouldHideCancelButton
185189
@brief Whether to hide the canel button, defaults to NO.
186190
*/

FirebaseAuthUI/FUIAuth.m

Lines changed: 25 additions & 308 deletions
Large diffs are not rendered by default.

FirebaseAuthUI/FUIAuthBaseViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ - (void)decrementActivity {
396396
- (void)cancelAuthorization {
397397
[self dismissNavigationControllerAnimated:YES completion:^{
398398
NSError *error = [FUIAuthErrorUtils userCancelledSignInError];
399-
[self.authUI invokeResultCallbackWithAuthDataResult:nil error:error];
399+
[self.authUI invokeResultCallbackWithAuthDataResult:nil URL:nil error:error];
400400
}];
401401
}
402402

FirebaseAuthUI/FUIAuthPickerViewController.m

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,6 @@
2525
#import "FUIEmailEntryViewController.h"
2626
#import "FUIPrivacyAndTermsOfServiceView.h"
2727

28-
29-
/** @var kErrorUserInfoEmailKey
30-
@brief The key for the email address in the userinfo dictionary of a sign in error.
31-
*/
32-
static NSString *const kErrorUserInfoEmailKey = @"FIRAuthErrorUserInfoEmailKey";
33-
34-
/** @var kEmailButtonAccessibilityID
35-
@brief The Accessibility Identifier for the @c email sign in button.
36-
*/
37-
static NSString *const kEmailButtonAccessibilityID = @"EmailButtonAccessibilityID";
38-
3928
/** @var kSignInButtonWidth
4029
@brief The width of the sign in buttons.
4130
*/
@@ -98,10 +87,7 @@ - (void)viewDidLoad {
9887
action:nil];
9988

10089
NSInteger numberOfButtons = self.authUI.providers.count;
101-
BOOL showEmailButton = !self.authUI.signInWithEmailHidden;
102-
if (showEmailButton) {
103-
++numberOfButtons;
104-
}
90+
10591
CGFloat buttonContainerViewHeight =
10692
kSignInButtonHeight * numberOfButtons + kSignInButtonVerticalMargin * (numberOfButtons);
10793
CGRect buttonContainerViewFrame = CGRectMake(0, 0, kSignInButtonWidth, buttonContainerViewHeight);
@@ -121,22 +107,6 @@ - (void)viewDidLoad {
121107
buttonFrame.origin.y += (kSignInButtonHeight + kSignInButtonVerticalMargin);
122108
}
123109

124-
if (showEmailButton) {
125-
UIColor *emailButtonBackgroundColor =
126-
[UIColor colorWithRed:208.f/255.f green:2.f/255.f blue:27.f/255.f alpha:1.0];
127-
UIButton *emailButton =
128-
[[FUIAuthSignInButton alloc] initWithFrame:buttonFrame
129-
image:[FUIAuthUtils imageNamed:@"ic_email"
130-
fromBundle:FUIAuthBundleName]
131-
text:FUILocalizedString(kStr_SignInWithEmail)
132-
backgroundColor:emailButtonBackgroundColor
133-
textColor:[UIColor whiteColor]];
134-
[emailButton addTarget:self
135-
action:@selector(signInWithEmail)
136-
forControlEvents:UIControlEventTouchUpInside];
137-
emailButton.accessibilityIdentifier = kEmailButtonAccessibilityID;
138-
[_buttonContainerView addSubview:emailButton];
139-
}
140110
_privacyPolicyAndTOSView.authUI = self.authUI;
141111
[_privacyPolicyAndTOSView useFullMessage];
142112
}
@@ -154,16 +124,6 @@ - (void)viewDidLayoutSubviews {
154124

155125
#pragma mark - Actions
156126

157-
- (void)signInWithEmail {
158-
UIViewController *controller;
159-
if ([self.authUI.delegate respondsToSelector:@selector(emailEntryViewControllerForAuthUI:)]) {
160-
controller = [self.authUI.delegate emailEntryViewControllerForAuthUI:self.authUI];
161-
} else {
162-
controller = [[FUIEmailEntryViewController alloc] initWithAuthUI:self.authUI];
163-
}
164-
[self pushViewController:controller];
165-
}
166-
167127
- (void)didTapSignInButton:(FUIAuthSignInButton *)button {
168128
[self.authUI signInWithProviderUI:button.providerUI
169129
presentingViewController:self

FirebaseAuthUI/FUIAuth_Internal.h

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,49 @@
1616

1717
#import "FUIAuth.h"
1818

19+
@class FUIAuthBaseViewController;
20+
21+
22+
/** @typedef FUIEmailHintSignInCallback
23+
@brief The type of block invoked when an emailHint sign-in event completes.
24+
25+
@param authResult Optionally; Result of sign-in request containing both the user and
26+
the additional user info associated with the user.
27+
@param error Optionally; the error which occurred - or nil if the request was successful.
28+
@param credential Optionally; The credential used to sign-in.
29+
*/
30+
typedef void (^FUIEmailHintSignInCallback)(FIRAuthDataResult *_Nullable authResult,
31+
NSError *_Nullable error,
32+
FIRAuthCredential *_Nullable credential);
33+
1934
NS_ASSUME_NONNULL_BEGIN
2035

36+
37+
38+
@protocol FUIEmailAuthProvider <NSObject>
39+
40+
- (void)handleAccountLinkingForEmail:(NSString *)email
41+
newCredential:(FIRAuthCredential *)newCredential
42+
presentingViewController:(UIViewController *)presentingViewController
43+
signInResult:(_Nullable FIRAuthResultCallback)result;
44+
45+
- (void)signInWithEmailHint:(NSString *)emailHint
46+
presentingViewController:(FUIAuthBaseViewController *)presentingViewController
47+
originalError:(NSError *)originalError
48+
completion:(FUIEmailHintSignInCallback)completion;
49+
50+
@end
51+
2152
@interface FUIAuth ()
2253

2354
/** @fn invokeResultCallbackWithAuthDataResult:error:
2455
@brief Invokes the auth UI result callback.
2556
@param authDataResult The sign in data result, if any.
57+
@param url The url, if any.
2658
@param error The error which occurred, if any.
2759
*/
2860
- (void)invokeResultCallbackWithAuthDataResult:(nullable FIRAuthDataResult *)authDataResult
61+
URL:(nullable NSURL *)url
2962
error:(nullable NSError *)error;
3063

3164
/** @fn invokeOperationCallback:error:
@@ -45,7 +78,7 @@ NS_ASSUME_NONNULL_BEGIN
4578

4679
/** @fn signInWithProviderUI:presentingViewController:defaultValue:
4780
@brief Signs in with specified provider.
48-
@see FUIAuthDelegate.authUI:didSignInWithAuthDataResult:error: for method callback.
81+
@see FUIAuthDelegate.authUI:didSignInWithAuthDataResult:URL:error: for method callback.
4982
@param providerUI The authentication provider used for signing in.
5083
@param presentingViewController The view controller used to present the UI.
5184
@param defaultValue The provider default initialization value (e.g. email or phone number)
@@ -55,6 +88,8 @@ NS_ASSUME_NONNULL_BEGIN
5588
presentingViewController:(UIViewController *)presentingViewController
5689
defaultValue:(nullable NSString *)defaultValue;
5790

91+
@property(nonatomic, weak) id<FUIEmailAuthProvider> emailAuthProvider;
92+
5893
@end
5994

6095
NS_ASSUME_NONNULL_END

FirebaseAuthUI/FirebaseAuthUI.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,3 @@ FOUNDATION_EXPORT const unsigned char FirebaseAuthUIVersionString[];
3131
#import "FUIAuthErrorUtils.h"
3232
#import "FUIAuthPickerViewController.h"
3333
#import "FUIAuthProvider.h"
34-
#import "FUIEmailEntryViewController.h"
35-
#import "FUIPasswordRecoveryViewController.h"
36-
#import "FUIPasswordSignInViewController.h"
37-
#import "FUIPasswordSignUpViewController.h"
38-
#import "FUIPasswordVerificationViewController.h"

FirebaseAuthUI/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ This instance can then be configured with the providers you wish to support:
8787
import FirebaseUI
8888

8989
let providers: [FUIAuthProvider] = [
90+
FUIEmailAuth(),
9091
FUIGoogleAuth(),
9192
FUIFacebookAuth(),
9293
FUITwitterAuth(),
@@ -102,6 +103,7 @@ self.authUI?.providers = providers
102103
// ...
103104

104105
NSArray<id<FUIAuthProvider>> *providers = @[
106+
[[FUIEmailAuth alloc] init],
105107
[[FUIGoogleAuth alloc] init],
106108
[[FUIFacebookAuth alloc] init],
107109
[[FUITwitterAuth alloc] init],

FirebaseEmailAuthUI/FUIEmailAuth.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
//
2+
// Copyright (c) 2018 Email Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
#import "FUIAuthProvider.h"
18+
19+
@class FUIAuth;
20+
@class FIRActionCodeSettings;
21+
@class FUIEmailEntryViewController;
22+
@class FUIPasswordSignInViewController;
23+
@class FUIPasswordSignUpViewController;
24+
@class FUIPasswordRecoveryViewController;
25+
@class FUIPasswordVerificationViewController;
26+
27+
NS_ASSUME_NONNULL_BEGIN
28+
29+
/** @class FUIEmailAuth
30+
@brief AuthUI components for Email Sign In.
31+
*/
32+
@interface FUIEmailAuth : NSObject <FUIAuthProvider>
33+
34+
- (instancetype)initAuthAuthUI:(FUIAuth *)authUI
35+
signInMethod:(NSString *)signInMethod
36+
forceSameDevice:(BOOL)forceSameDevice
37+
allowNewEmailAccounts:(BOOL)allowNewEmailAccounts
38+
actionCodeSetting:(FIRActionCodeSettings *)actionCodeSettings;
39+
40+
41+
/** @property signInMethod.
42+
@brief Defines the sign in method for FIREmailAuthProvider.
43+
This can be one of the following string constants:
44+
- FIREmailLinkAuthSignInMethod
45+
- FIREmailPasswordAuthSignInMethod (default).
46+
*/
47+
@property(nonatomic, copy, readonly) NSString *signInMethod;
48+
49+
/** @property forceSameDevice.
50+
@brief Whether to force same device flow. If not, opening the link on a different device will
51+
display an error message. Note that this should be true when used with anonymous user
52+
upgrade flows. The default is false.
53+
*/
54+
@property(nonatomic, assign, readonly) BOOL forceSameDevice;
55+
56+
/** @property actionCodeSettings.
57+
@brief Defines the FIRActionCodeSettings configuration to use when sending the link. This gives
58+
the developer the ability to specify how the link can be handled, custom dynamic link,
59+
additional state in the deep link, etc.
60+
*/
61+
@property(nonatomic, strong, readonly) FIRActionCodeSettings *actionCodeSettings;
62+
63+
/** @property allowNewEmailAccounts
64+
@brief Whether to allow new user sign, defaults to YES.
65+
*/
66+
@property(nonatomic, assign, readonly) BOOL allowNewEmailAccounts;
67+
68+
/** @fn signInWithPresentingViewController:
69+
@brief Signs in with email auth provider.
70+
@see FUIAuthDelegate.authUI:didSignInWithAuthDataResult:URL:error: for method callback.
71+
@param presentingViewController The view controller used to present the UI.
72+
*/
73+
- (void)signInWithPresentingViewController:(UIViewController *)presentingViewController
74+
__attribute__((deprecated("This is deprecated API and will be removed in a future release."
75+
"Please use signInWithPresentingViewController:email:")));
76+
77+
/** @fn signInWithPresentingViewController:email:
78+
@brief Signs in with email auth provider.
79+
@see FUIAuthDelegate.authUI:didSignInWithAuthDataResult:URL:error: for method callback.
80+
@param presentingViewController The view controller used to present the UI.
81+
@param email The default email address.
82+
*/
83+
- (void)signInWithPresentingViewController:(UIViewController *)presentingViewController
84+
email:(nullable NSString *)email;
85+
86+
87+
@end
88+
89+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)