Skip to content

Commit 574188f

Browse files
committed
implement Google sign in
1 parent 5308fdf commit 574188f

File tree

5 files changed

+185
-15
lines changed

5 files changed

+185
-15
lines changed

samples/objc/FirebaseUIChat/AppDelegate.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,24 @@
1717
#import "AppDelegate.h"
1818
@import Firebase;
1919

20+
// Uncomment when using frawemorks
21+
//@import FirebaseAuthUI;
22+
#import <FirebaseAuthUI.h>
23+
2024
@implementation AppDelegate
2125

2226
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
2327
[FIRApp configure];
2428
return YES;
2529
}
30+
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options {
31+
32+
NSString *sourceApp = options[UIApplicationOpenURLOptionsSourceApplicationKey];
33+
34+
if ([FIRAuthUI.defaultAuthUI handleOpenURL:url sourceApplication:sourceApp]) {
35+
return YES;
36+
}
37+
return NO;
38+
}
2639

2740
@end

samples/objc/FirebaseUIChat/Base.lproj/Main.storyboard

Lines changed: 91 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,101 @@
117117
<point key="canvasLocation" x="380" y="315"/>
118118
</scene>
119119
<!--Auth View Controller-->
120-
<scene sceneID="8ct-Gf-RI6">
120+
<scene sceneID="AaL-89-8RF">
121121
<objects>
122-
<viewController storyboardIdentifier="FIRAuthViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="LmU-7s-TNo" customClass="FIRAuthViewController" sceneMemberID="viewController">
123-
<layoutGuides>
124-
<viewControllerLayoutGuide type="top" id="QAT-HV-OZV"/>
125-
<viewControllerLayoutGuide type="bottom" id="jNo-4u-MUs"/>
126-
</layoutGuides>
127-
<view key="view" contentMode="scaleToFill" id="TYT-qz-Ma5">
122+
<tableViewController storyboardIdentifier="FIRAuthViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="CNE-cz-Qwp" customClass="FIRAuthViewController" sceneMemberID="viewController">
123+
<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">
128124
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
129125
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
130-
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
131-
</view>
132-
</viewController>
133-
<placeholder placeholderIdentifier="IBFirstResponder" id="I5a-Mj-GLr" userLabel="First Responder" sceneMemberID="firstResponder"/>
126+
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
127+
<toolbar key="tableFooterView" opaque="NO" clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="83E-4Z-ptP">
128+
<rect key="frame" x="0.0" y="397" width="600" height="44"/>
129+
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
130+
<items>
131+
<barButtonItem style="plain" systemItem="flexibleSpace" id="o3y-o4-Gpu"/>
132+
<barButtonItem title="Sign In" id="bgV-bu-PcA">
133+
<connections>
134+
<action selector="onAuthorization:" destination="CNE-cz-Qwp" id="8RX-tN-gBO"/>
135+
</connections>
136+
</barButtonItem>
137+
<barButtonItem style="plain" systemItem="flexibleSpace" id="PyK-ro-bxx"/>
138+
</items>
139+
</toolbar>
140+
<sections>
141+
<tableViewSection headerTitle="Signed In" id="PRj-zg-0nr">
142+
<cells>
143+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" textLabel="l96-xc-PHH" style="IBUITableViewCellStyleDefault" id="ORf-bf-Sq2">
144+
<rect key="frame" x="0.0" y="50" width="600" height="44"/>
145+
<autoresizingMask key="autoresizingMask"/>
146+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="ORf-bf-Sq2" id="roJ-pJ-jY5">
147+
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
148+
<autoresizingMask key="autoresizingMask"/>
149+
<subviews>
150+
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Not Signed In" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="l96-xc-PHH">
151+
<rect key="frame" x="15" y="0.0" width="570" height="43"/>
152+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
153+
<fontDescription key="fontDescription" type="system" pointSize="16"/>
154+
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
155+
<nil key="highlightedColor"/>
156+
</label>
157+
</subviews>
158+
</tableViewCellContentView>
159+
</tableViewCell>
160+
</cells>
161+
</tableViewSection>
162+
<tableViewSection headerTitle="Name" id="0YA-IY-hOV">
163+
<cells>
164+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="kCl-ip-jc2">
165+
<rect key="frame" x="0.0" y="145" width="600" height="44"/>
166+
<autoresizingMask key="autoresizingMask"/>
167+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="kCl-ip-jc2" id="dm4-D7-IWN">
168+
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
169+
<autoresizingMask key="autoresizingMask"/>
170+
</tableViewCellContentView>
171+
</tableViewCell>
172+
</cells>
173+
</tableViewSection>
174+
<tableViewSection headerTitle="Email" id="Y94-bQ-cWH">
175+
<cells>
176+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="MCw-zF-UTn">
177+
<rect key="frame" x="0.0" y="240" width="600" height="44"/>
178+
<autoresizingMask key="autoresizingMask"/>
179+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="MCw-zF-UTn" id="ea1-oT-1Py">
180+
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
181+
<autoresizingMask key="autoresizingMask"/>
182+
</tableViewCellContentView>
183+
</tableViewCell>
184+
</cells>
185+
</tableViewSection>
186+
<tableViewSection headerTitle="UID" id="Yxe-jV-t3o">
187+
<cells>
188+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" id="EWm-GE-IZV">
189+
<rect key="frame" x="0.0" y="335" width="600" height="44"/>
190+
<autoresizingMask key="autoresizingMask"/>
191+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="EWm-GE-IZV" id="ISG-G9-H8V">
192+
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
193+
<autoresizingMask key="autoresizingMask"/>
194+
</tableViewCellContentView>
195+
</tableViewCell>
196+
</cells>
197+
</tableViewSection>
198+
</sections>
199+
<connections>
200+
<outlet property="dataSource" destination="CNE-cz-Qwp" id="MrI-Jx-5UJ"/>
201+
<outlet property="delegate" destination="CNE-cz-Qwp" id="KFk-25-IpR"/>
202+
</connections>
203+
</tableView>
204+
<connections>
205+
<outlet property="btnAuthorization" destination="bgV-bu-PcA" id="bBY-yq-fyj"/>
206+
<outlet property="cellEmail" destination="MCw-zF-UTn" id="sw3-8D-gut"/>
207+
<outlet property="cellName" destination="kCl-ip-jc2" id="C8k-DT-KVQ"/>
208+
<outlet property="cellSignIn" destination="ORf-bf-Sq2" id="5Lp-Ik-8fw"/>
209+
<outlet property="cellUID" destination="EWm-GE-IZV" id="eTu-Vt-UCP"/>
210+
</connections>
211+
</tableViewController>
212+
<placeholder placeholderIdentifier="IBFirstResponder" id="1w1-3x-wCC" userLabel="First Responder" sceneMemberID="firstResponder"/>
134213
</objects>
135-
<point key="canvasLocation" x="1761" y="315"/>
214+
<point key="canvasLocation" x="1713" y="315"/>
136215
</scene>
137216
</scenes>
138217
</document>

samples/objc/FirebaseUIChat/Info.plist

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
<string>1.0</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
21+
<key>CFBundleURLTypes</key>
22+
<array>
23+
<dict>
24+
<key>CFBundleTypeRole</key>
25+
<string>Editor</string>
26+
<key>CFBundleURLSchemes</key>
27+
<array>
28+
<string>REVERSED_CLIENT_ID</string>
29+
</array>
30+
</dict>
31+
</array>
2132
<key>CFBundleVersion</key>
2233
<string>1</string>
2334
<key>LSRequiresIPhoneOS</key>

samples/objc/FirebaseUIChat/Samples/Auth/FIRAuthViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818

1919
#import <UIKit/UIKit.h>
2020

21-
@interface FIRAuthViewController : UIViewController
21+
@interface FIRAuthViewController : UITableViewController
2222

2323
@end

samples/objc/FirebaseUIChat/Samples/Auth/FIRAuthViewController.m

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,85 @@
1717
//
1818

1919
#import "FIRAuthViewController.h"
20+
@import Firebase;
21+
22+
// Uncomment when using frawemorks
23+
//@import FirebaseAuthUI;
24+
#import <FirebaseAuthUI.h>
25+
// Uncomment when using frawemorks
26+
//@import FirebaseGoogleAuthUI;
27+
#import <FIRGoogleAuthUI.h>
2028

2129
@interface FIRAuthViewController ()
30+
@property (weak, nonatomic) IBOutlet UITableViewCell *cellSignIn;
31+
@property (weak, nonatomic) IBOutlet UITableViewCell *cellName;
32+
@property (weak, nonatomic) IBOutlet UITableViewCell *cellEmail;
33+
@property (weak, nonatomic) IBOutlet UITableViewCell *cellUID;
34+
@property (weak, nonatomic) IBOutlet UIBarButtonItem *btnAuthorization;
35+
36+
@property (nonatomic) FIRAuth *auth;
37+
@property (nonatomic) FIRAuthUI *authUI;
38+
@property (nonatomic) FIRUser *authUser;
39+
40+
@property (nonatomic) FIRAuthStateDidChangeListenerHandle authStateDidChangeHandle;
2241

2342
@end
2443

2544
@implementation FIRAuthViewController
2645

2746
- (void)viewDidLoad {
28-
[super viewDidLoad];
29-
// Do any additional setup after loading the view.
47+
[super viewDidLoad];
48+
49+
self.auth = [FIRAuth auth];
50+
self.authUI = [FIRAuthUI defaultAuthUI];
51+
}
52+
53+
- (void)viewWillAppear:(BOOL)animated {
54+
[super viewWillAppear:animated];
55+
56+
NSString *googleId = [[FIRApp defaultApp] options].clientID;
57+
NSArray<id<FIRAuthProviderUI>> *providers = [NSArray arrayWithObjects:[[FIRGoogleAuthUI alloc] initWithClientID:googleId] , nil];
58+
_authUI.providers = providers;
59+
60+
self.authStateDidChangeHandle = [self.auth addAuthStateDidChangeListener:^(FIRAuth * _Nonnull auth, FIRUser * _Nullable user) {
61+
[self updateUI:auth withUser:user];
62+
}];
63+
64+
65+
}
66+
67+
- (void)updateUI:(FIRAuth * _Nonnull) auth withUser:(FIRUser * _Nullable) user {
68+
self.authUser = user;
69+
if (user) {
70+
self.cellSignIn.textLabel.text = @"YES";
71+
self.cellName.textLabel.text = user.displayName;
72+
self.cellEmail.textLabel.text = user.email;
73+
self.cellUID.textLabel.text = user.uid;
74+
75+
self.btnAuthorization.title = @"Sign Out";
76+
} else {
77+
self.cellSignIn.textLabel.text = @"NO";
78+
self.cellName.textLabel.text = @"";
79+
self.cellEmail.textLabel.text = @"";
80+
self.cellUID.textLabel.text = @"";
81+
82+
self.btnAuthorization.title = @"Sign In";
83+
}
84+
3085
}
3186

87+
- (IBAction)onAuthorization:(id)sender {
88+
if (!self.authUser) {
89+
UIViewController *controller = [self.authUI authViewController];
90+
[self presentViewController:controller animated:YES completion:nil];
91+
} else {
92+
NSError *error;
93+
[self.auth signOut:&error];
94+
if (error) {
95+
NSLog(@"Sign out error: %@", error);
96+
}
97+
}
98+
}
3299

33100

34101
@end

0 commit comments

Comments
 (0)