Skip to content

Commit ac7269d

Browse files
committed
add IDP selection in sample project
add custom TOS url to obj-c sample
1 parent 0edbbbe commit ac7269d

File tree

4 files changed

+329
-41
lines changed

4 files changed

+329
-41
lines changed

samples/objc/FirebaseUI-demo-objc/Base.lproj/Main.storyboard

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
<scene sceneID="AaL-89-8RF">
128128
<objects>
129129
<tableViewController storyboardIdentifier="FIRAuthViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="CNE-cz-Qwp" customClass="FIRAuthViewController" sceneMemberID="viewController">
130-
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="pZ2-Vi-FKX">
130+
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="default" allowsMultipleSelection="YES" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="pZ2-Vi-FKX">
131131
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
132132
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
133133
<color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
@@ -180,10 +180,82 @@
180180
</tableViewCell>
181181
</cells>
182182
</tableViewSection>
183+
<tableViewSection headerTitle="IDPs" id="PVw-r0-CZU">
184+
<cells>
185+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" textLabel="bNY-j2-MJU" style="IBUITableViewCellStyleDefault" id="2Oh-0M-qfT">
186+
<rect key="frame" x="0.0" y="201" width="375" height="44"/>
187+
<autoresizingMask key="autoresizingMask"/>
188+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="2Oh-0M-qfT" id="TvY-i4-8Zf">
189+
<frame key="frameInset" width="375" height="43"/>
190+
<autoresizingMask key="autoresizingMask"/>
191+
<subviews>
192+
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Email" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="bNY-j2-MJU">
193+
<frame key="frameInset" minX="15" width="345" height="43"/>
194+
<autoresizingMask key="autoresizingMask"/>
195+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
196+
<nil key="textColor"/>
197+
<nil key="highlightedColor"/>
198+
</label>
199+
</subviews>
200+
</tableViewCellContentView>
201+
</tableViewCell>
202+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" indentationWidth="10" textLabel="uy2-M7-fjT" style="IBUITableViewCellStyleDefault" id="xWg-io-2Mh">
203+
<rect key="frame" x="0.0" y="245" width="375" height="44"/>
204+
<autoresizingMask key="autoresizingMask"/>
205+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="xWg-io-2Mh" id="yTE-jh-CKv">
206+
<frame key="frameInset" width="375" height="43"/>
207+
<autoresizingMask key="autoresizingMask"/>
208+
<subviews>
209+
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Google" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="uy2-M7-fjT">
210+
<frame key="frameInset" minX="15" width="345" height="43"/>
211+
<autoresizingMask key="autoresizingMask"/>
212+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
213+
<nil key="textColor"/>
214+
<nil key="highlightedColor"/>
215+
</label>
216+
</subviews>
217+
</tableViewCellContentView>
218+
</tableViewCell>
219+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" indentationWidth="10" textLabel="VO0-E4-us7" style="IBUITableViewCellStyleDefault" id="UHh-u9-c6X">
220+
<rect key="frame" x="0.0" y="289" width="375" height="44"/>
221+
<autoresizingMask key="autoresizingMask"/>
222+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="UHh-u9-c6X" id="kWa-iB-lBj">
223+
<frame key="frameInset" width="375" height="43"/>
224+
<autoresizingMask key="autoresizingMask"/>
225+
<subviews>
226+
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Facebook" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="VO0-E4-us7">
227+
<frame key="frameInset" minX="15" width="345" height="43"/>
228+
<autoresizingMask key="autoresizingMask"/>
229+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
230+
<nil key="textColor"/>
231+
<nil key="highlightedColor"/>
232+
</label>
233+
</subviews>
234+
</tableViewCellContentView>
235+
</tableViewCell>
236+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" indentationWidth="10" textLabel="xVM-YB-XaA" style="IBUITableViewCellStyleDefault" id="6bt-FY-pRU">
237+
<rect key="frame" x="0.0" y="333" width="375" height="44"/>
238+
<autoresizingMask key="autoresizingMask"/>
239+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="6bt-FY-pRU" id="8RC-g4-krD">
240+
<frame key="frameInset" width="375" height="43"/>
241+
<autoresizingMask key="autoresizingMask"/>
242+
<subviews>
243+
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Twitter" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="xVM-YB-XaA">
244+
<frame key="frameInset" minX="15" width="345" height="43"/>
245+
<autoresizingMask key="autoresizingMask"/>
246+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
247+
<nil key="textColor"/>
248+
<nil key="highlightedColor"/>
249+
</label>
250+
</subviews>
251+
</tableViewCellContentView>
252+
</tableViewCell>
253+
</cells>
254+
</tableViewSection>
183255
<tableViewSection headerTitle="Name" id="0YA-IY-hOV">
184256
<cells>
185257
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="kCl-ip-jc2">
186-
<rect key="frame" x="0.0" y="201" width="375" height="44"/>
258+
<rect key="frame" x="0.0" y="434" width="375" height="44"/>
187259
<autoresizingMask key="autoresizingMask"/>
188260
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="kCl-ip-jc2" id="dm4-D7-IWN">
189261
<frame key="frameInset" width="375" height="43"/>
@@ -195,7 +267,7 @@
195267
<tableViewSection headerTitle="Email" id="Y94-bQ-cWH">
196268
<cells>
197269
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="MCw-zF-UTn">
198-
<rect key="frame" x="0.0" y="302" width="375" height="44"/>
270+
<rect key="frame" x="0.0" y="535" width="375" height="44"/>
199271
<autoresizingMask key="autoresizingMask"/>
200272
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="MCw-zF-UTn" id="ea1-oT-1Py">
201273
<frame key="frameInset" width="375" height="43"/>
@@ -207,7 +279,7 @@
207279
<tableViewSection headerTitle="UID" id="Yxe-jV-t3o">
208280
<cells>
209281
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" id="EWm-GE-IZV">
210-
<rect key="frame" x="0.0" y="403" width="375" height="44"/>
282+
<rect key="frame" x="0.0" y="636" width="375" height="44"/>
211283
<autoresizingMask key="autoresizingMask"/>
212284
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="EWm-GE-IZV" id="ISG-G9-H8V">
213285
<frame key="frameInset" width="375" height="43"/>
@@ -219,7 +291,7 @@
219291
<tableViewSection headerTitle="Provider Access Token" id="E31-4c-QDa">
220292
<cells>
221293
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" textLabel="k9f-GH-UBQ" style="IBUITableViewCellStyleDefault" id="mdj-SS-dqJ">
222-
<rect key="frame" x="0.0" y="504" width="375" height="44"/>
294+
<rect key="frame" x="0.0" y="737" width="375" height="44"/>
223295
<autoresizingMask key="autoresizingMask"/>
224296
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="mdj-SS-dqJ" id="oCT-Ra-9l7">
225297
<frame key="frameInset" width="375" height="43"/>
@@ -240,7 +312,7 @@
240312
<tableViewSection headerTitle="Provider ID Token" id="GaU-wa-aFK">
241313
<cells>
242314
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" textLabel="M61-v5-jhZ" style="IBUITableViewCellStyleDefault" id="b45-X5-eC9">
243-
<rect key="frame" x="0.0" y="605" width="375" height="44"/>
315+
<rect key="frame" x="0.0" y="838" width="375" height="44"/>
244316
<autoresizingMask key="autoresizingMask"/>
245317
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="b45-X5-eC9" id="ofC-qT-5cz">
246318
<frame key="frameInset" width="375" height="43"/>

samples/objc/FirebaseUI-demo-objc/Samples/Auth/FIRAuthViewController.m

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@
2828

2929
#import "FIRCustomAuthPickerViewController.h"
3030

31+
typedef enum : NSUInteger {
32+
kSectionsSettings = 0,
33+
kSectionsProviders,
34+
kSectionsName,
35+
kSectionsEmail,
36+
kSectionsUID,
37+
kSectionsAccessToken,
38+
kSectionsIDToken
39+
} UISections;
40+
41+
typedef enum : NSUInteger {
42+
kIDPEmail = 0,
43+
kIDPGoogle,
44+
kIDPFacebook,
45+
kIDPTwitter
46+
} FIRProviders;
47+
48+
NSString * const kFirebaseTermsOfService = @"https://firebase.google.com/terms/";
49+
3150
@interface FIRAuthViewController () <FIRAuthUIDelegate>
3251
@property (weak, nonatomic) IBOutlet UITableViewCell *cellSignIn;
3352
@property (weak, nonatomic) IBOutlet UITableViewCell *cellName;
@@ -61,21 +80,35 @@ - (void)viewDidLoad {
6180

6281
self.auth = [FIRAuth auth];
6382
self.authUI = [FIRAuthUI defaultAuthUI];
83+
84+
self.authUI.TOSURL = [NSURL URLWithString:kFirebaseTermsOfService];
85+
6486
//set AuthUI Delegate
6587
[self onAuthUIDelegateChanged:nil];
6688

89+
//select all Identety providers
90+
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:kIDPEmail
91+
inSection:kSectionsProviders]
92+
animated:NO
93+
scrollPosition:UITableViewScrollPositionNone];
94+
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:kIDPGoogle
95+
inSection:kSectionsProviders]
96+
animated:NO
97+
scrollPosition:UITableViewScrollPositionNone];
98+
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:kIDPFacebook
99+
inSection:kSectionsProviders]
100+
animated:NO
101+
scrollPosition:UITableViewScrollPositionNone];
102+
[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:kIDPTwitter
103+
inSection:kSectionsProviders]
104+
animated:NO
105+
scrollPosition:UITableViewScrollPositionNone];
106+
67107
}
68108

69109
- (void)viewWillAppear:(BOOL)animated {
70110
[super viewWillAppear:animated];
71111

72-
NSArray<id<FIRAuthProviderUI>> *providers = [NSArray arrayWithObjects:
73-
[[FIRGoogleAuthUI alloc] init],
74-
[[FIRFacebookAuthUI alloc] init],
75-
[[FIRTwitterAuthUI alloc] init],
76-
nil];
77-
_authUI.providers = providers;
78-
79112
__weak FIRAuthViewController *weakSelf = self;
80113
self.authStateDidChangeHandle = [self.auth addAuthStateDidChangeListener:^(FIRAuth * _Nonnull auth, FIRUser * _Nullable user) {
81114
[weakSelf updateUI:auth withUser:user];
@@ -119,7 +152,13 @@ - (void)updateUI:(FIRAuth * _Nonnull) auth withUser:(FIRUser * _Nullable) user {
119152
self.cellAccessToken.textLabel.text = [self getAllAccessTokens];
120153
self.cellIdToken.textLabel.text = [self getAllIdTokens];
121154

155+
NSArray *selectedRows = [self.tableView indexPathsForSelectedRows];
122156
[self.tableView reloadData];
157+
for (NSIndexPath *path in selectedRows) {
158+
[self.tableView selectRowAtIndexPath:path
159+
animated:NO
160+
scrollPosition:UITableViewScrollPositionNone];
161+
}
123162
}
124163
- (IBAction)onAuthUIDelegateChanged:(UISwitch *)sender {
125164
_isCustomAuthDelegateSelected = sender ? sender.isOn : NO;
@@ -132,6 +171,10 @@ - (IBAction)onAuthUIDelegateChanged:(UISwitch *)sender {
132171

133172
- (IBAction)onAuthorization:(id)sender {
134173
if (!self.auth.currentUser) {
174+
175+
_authUI.providers = [self getListOfIDPs];
176+
_authUI.signInWithEmailHidden = ![self isEmailEnabled];
177+
135178
UINavigationController *controller = [self.authUI authViewController];
136179
if (_isCustomAuthDelegateSelected) {
137180
controller.navigationBar.hidden = YES;
@@ -159,7 +202,6 @@ - (void)authUI:(FIRAuthUI *)authUI didSignInWithUser:(nullable FIRUser *)user er
159202
}
160203
}
161204

162-
163205
#pragma mark - Helper Methods
164206

165207
- (NSString *)getAllAccessTokens {
@@ -201,4 +243,38 @@ - (void)showAlert:(NSString *)message {
201243

202244
}
203245

246+
- (NSArray *)getListOfIDPs {
247+
NSArray<NSIndexPath *> *selectedRows = [self.tableView indexPathsForSelectedRows];
248+
NSMutableArray *providers = [NSMutableArray new];
249+
250+
for (NSIndexPath *indexPath in selectedRows) {
251+
if (indexPath.section == kSectionsProviders) {
252+
switch (indexPath.row) {
253+
case kIDPGoogle:
254+
[providers addObject:[[FIRGoogleAuthUI alloc] init]];
255+
break;
256+
case kIDPFacebook:
257+
[providers addObject:[[FIRFacebookAuthUI alloc] init]];
258+
break;
259+
case kIDPTwitter:
260+
[providers addObject:[[FIRTwitterAuthUI alloc] init]];
261+
break;
262+
263+
default:
264+
break;
265+
}
266+
}
267+
}
268+
269+
return providers;
270+
}
271+
272+
- (BOOL)isEmailEnabled {
273+
NSArray<NSIndexPath *> *selectedRows = [self.tableView indexPathsForSelectedRows];
274+
return [selectedRows containsObject:[NSIndexPath
275+
indexPathForRow:kIDPEmail
276+
inSection:kSectionsProviders]];
277+
}
278+
279+
204280
@end

0 commit comments

Comments
 (0)