Skip to content

Commit 4b72a0c

Browse files
committed
Adding FirebaseAppDelegate and FirebaseLoginViewController
1 parent e9807a7 commit 4b72a0c

File tree

2 files changed

+103
-4
lines changed

2 files changed

+103
-4
lines changed

README.md

Lines changed: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,105 @@ FirebaseDataSource acts as a generic data source by providing common information
343343

344344
## FirebaseUI Auth API
345345

346-
### FirebaseAuthProvider
346+
### FirebaseAppDelegate
347+
`FirebaseAppDelegate` is replacement for the standard `AppDelegate` and provides setup features necessary for authentication to work. If you plan on using FirebaseUI authentication features, your `AppDelegate` should subclass `FirebaseAppDelegate` like so:
348+
349+
#### Objective-C
350+
```objective-c
351+
// AppDelegate.h
352+
#import <UIKit/UIKit.h>
353+
#import <FirebaseUI/FirebaseUI.h>
354+
355+
@interface AppDelegate : FirebaseAppDelegate
356+
357+
@end
358+
359+
// AppDelegate.m
360+
#import "AppDelegate.h"
361+
362+
@implementation AppDelegate
363+
364+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
365+
[super application:application didFinishLaunchingWithOptions:launchOptions];
366+
// Override point for customization after application launch.
367+
368+
return YES;
369+
}
370+
...
371+
372+
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(nonnull id)annotation {
373+
[super application:app openURL:url sourceApplication:sourceApplication annotation:annotation];
374+
// Override point for customization.
375+
376+
return YES;
377+
}
378+
379+
@end
380+
```
381+
382+
#### Swift
383+
```swift
384+
import UIKit
385+
import FirebaseUI
386+
387+
@UIApplicationMain
388+
class AppDelegate: FirebaseAppDelegate {
389+
390+
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
391+
super.application(application, launchOptions);
392+
// Override point for customization after application launch.
393+
394+
return true
395+
}
396+
...
397+
398+
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
399+
super.application(application, url, sourceApplication, annotation);
400+
// Override point for customization.
401+
402+
return true
403+
}
404+
}
405+
```
406+
407+
### FirebaseLoginViewController
408+
`FirebaseLoginViewContoller` quickly adds a headful UI flow to your application. This flow supports email/password login, as well as social providers (Facebook, Google, Twitter). Using this, you can easily guide users through the login journey, get the current user's state, and log the user out. This view looks like:
409+
410+
![FirebaseLoginViewController with all providers enabled](https://raw.github.com/firebase/firebaseui-ios/tree/master/docs/FirebaseLoginViewController.png)
411+
412+
Code to create this view is below:
413+
414+
#### Objective-C
415+
```objective-c
416+
Firebase *firebaseRef = [[Firebase alloc] initWithUrl:@"https://<YOUR-FIREBASE-APP>.firebaseio.com/"];
417+
FirebaseLoginViewController *loginViewController = [[FirebaseLoginViewController alloc] initWithRef:ref];
418+
[loginViewController enableProvider:kGoogleAuthProvider];
419+
[loginViewController enableProvider:kFacebookAuthProvider];
420+
[loginViewController enableProvider:kTwitterAuthProvider];
421+
[loginViewController enableProvider:kPasswordAuthProvider];
422+
[self presentViewController:self.loginViewController animated:YES completion:nil];
423+
...
424+
FAuthData *user = [loginViewController currentUser]; // Check the currently logged in user
425+
...
426+
[loginViewController logout]; // Log the current user out
427+
```
428+
429+
#### Swift
430+
```swift
431+
let firebaseRef = Firebase(url: "https://<YOUR-FIREBASE-APP>.firebaseio.com/")
432+
var loginViewController = FirebaseLoginViewController(ref: firebaseRef)
433+
loginViewController.enableProvider(kGoogleAuthProvider)
434+
loginViewController.enableProvider(kFacebookAuthProvider)
435+
loginViewController.enableProvider(kTwitterAuthProvider)
436+
loginViewController.enableProvider(kPasswordAuthProvider)
437+
self.presentViewController(loginViewController, animated: true, completion: nil)
438+
...
439+
var user: FAuthData = loginViewController.currentUser(); // Check the currently logged in user
440+
...
441+
loginViewController.logout(); // Log the current user out
442+
```
347443

348-
`FirebaseAuthProvider` is a superclass for all identity providers, providing a default constructor `[FirebaseAuthProvider initWithRef:authDelegate:]` as well as `login`, `logout`, and `configureProvider` methods to facilitate standard authentication across providers. `login` and `configureProvider` are unimplemented in the base implementation and will thrown an exception if called, so each provider should override these methods. `logout` is implemented to unauthenticate the given Firebase reference, and should always be called using `[super logout]` at the end of any subclass implementation.
349444

350-
`FirebaseAuthProvider` also registers a singleton authentication listener that monitors the global authentication state across all providers and will route `authProvider:onLogin:` and `onLogout` events appropriately.
351445

352446
### FirebaseFacebookAuthProvider
353447

@@ -370,7 +464,6 @@ facebookProvider.login()
370464
...
371465
facebookProvider.logout()
372466
```
373-
374467
### FirebaseGoogleAuthProvider
375468

376469
`FirebaseGoogleAuthProvider` is a wrapper around Google login. To enable this, visit the Auth tab of your Firebase Dashboard and enable this provider by checking the checkbox, then [create a new Google Project](https://developers.google.com/identity/sign-in/ios/start), download `GoogleServices-Info.plist`, and include it in your projct. You will also have to add several URL schemes to your "Info.plist". For more information about setup, see the Firebase [Google authentication docs](https://www.firebase.com/docs/ios/guide/login/google.html).
@@ -439,6 +532,12 @@ passwordProvider.login()
439532

440533
## Understanding FirebaseUI Auth's Internals
441534

535+
### FirebaseAuthProvider
536+
537+
`FirebaseAuthProvider` is a superclass for all identity providers, providing a default constructor `[FirebaseAuthProvider initWithRef:authDelegate:]` as well as `login`, `logout`, and `configureProvider` methods to facilitate standard authentication across providers. `login` and `configureProvider` are unimplemented in the base implementation and will thrown an exception if called, so each provider should override these methods. `logout` is implemented to unauthenticate the given Firebase reference, and should always be called using `[super logout]` at the end of any subclass implementation.
538+
539+
`FirebaseAuthProvider` also registers a singleton authentication listener that monitors the global authentication state across all providers and will route `authProvider:onLogin:` and `onLogout` events appropriately.
540+
442541
### FirebaseAuthDelegate and TwitterAuthDelegate protocols
443542

444543
Every authentication event is plumbed through `FirebaseAuthDelegate`, which has four methods:
41.6 KB
Loading

0 commit comments

Comments
 (0)