|
| 1 | +# FirebaseUI for iOS — Auth |
| 2 | + |
| 3 | +FirebaseUI is an open-source library for iOS that provides simple, customizable UI |
| 4 | +bindings on top of [Firebase](https://firebase.google.com) SDKs to eliminate |
| 5 | +boilerplate code and promote best practices. |
| 6 | + |
| 7 | +FirebaseUI provides a drop-in auth solution that handles the UI flows for |
| 8 | +signing in users with email addresses and passwords, Google Sign-In, and |
| 9 | +Facebook Login. It is built on top of [Firebase Auth](https://firebase.google.com/docs/auth). |
| 10 | + |
| 11 | +The FirebaseUI Auth component implement best practices for authentication on |
| 12 | +mobile devices and websites, which can maximize sign-in and sign-up conversion |
| 13 | +for your app. It also handles edge cases like account recovery and account |
| 14 | +linking that can be security sensitive and error-prone to handle correctly. |
| 15 | + |
| 16 | +FirebaseUI can be easily customized to fit in with the rest of your app's visual |
| 17 | + style, and it is open source, so you aren't constrained in realizing the user |
| 18 | + experience you want. |
| 19 | + |
| 20 | +Compatible FirebaseUI clients are also available for [Android](https://github.com/firebase/firebaseui-android/tree/master/auth) |
| 21 | +and [Web](https://github.com/firebase/firebaseui-web/tree/master/auth). |
| 22 | + |
| 23 | +## Table of Contents |
| 24 | + |
| 25 | +1. [Installation](#installation) |
| 26 | +2. [Usage instructions](#using-firebaseui-for-authentication) |
| 27 | +3. [Customization](#customizing-firebaseui-for-authentication) |
| 28 | + |
| 29 | +## Installation |
| 30 | +### Importing FirebaseUI components for auth |
| 31 | +Add the following line to your `Podfile`: |
| 32 | +```objective-c |
| 33 | +pod 'FirebaseUI/Auth' |
| 34 | +``` |
| 35 | + |
| 36 | +### Configuring sign-in providers |
| 37 | +To use FirebaseUI to authenticate users you first need to configure each provider you want to use in |
| 38 | +their own developer app settings. Please read the *Before you begin* section of the Firebase |
| 39 | +Auth guides at the following links: |
| 40 | +[Email and password](https://firebase.google.com/docs/auth/web/password-auth#before_you_begin) |
| 41 | +[Google](https://firebase.google.com/docs/auth/ios/google-signin#before_you_begin) |
| 42 | +[Facebook](https://firebase.google.com/docs/auth/ios/facebook-login#before_you_begin) |
| 43 | + |
| 44 | + |
| 45 | +## Using FirebaseUI for Authentication |
| 46 | + |
| 47 | +### Configuration |
| 48 | + |
| 49 | +All operations, callbacks, UI customizations are done through an `FIRAuthUI` |
| 50 | +instance. The `FIRAuthUI` instance associated with the default `FIRAuth` |
| 51 | +instance can be accessed as follows: |
| 52 | + |
| 53 | +```objective-c |
| 54 | +[FIRApp configure]; |
| 55 | +FIRAuthUI *authUI = [FIRAuthUI authUI]; |
| 56 | +authUI.delegate = self; // Set the delegate to receive callback. |
| 57 | +``` |
| 58 | + |
| 59 | +This instance can then be configured with the providers you wish to support: |
| 60 | + |
| 61 | +```objective-c |
| 62 | +FIRGoogleAuthUI *googleAuthUI = |
| 63 | + [[FIRGoogleAuthUI alloc] initWithClientID:kGoogleClientID]; |
| 64 | +FIRFacebookAuthUI *facebookAuthUI = |
| 65 | + [[FIRFacebookAuthUI alloc] initWithAppID:kFacebookAppID]; |
| 66 | +authUI.providers = @[ googleAuthUI, facebookAuthUI]; |
| 67 | +``` |
| 68 | +
|
| 69 | +For Google sign in support, add custom URL schemes to your Xcode project |
| 70 | +(step 1 of the [implement Google Sign-In documentation](https://developers.google.com/firebase/docs/auth/ios/google-signin#2_implement_google_sign-in)). |
| 71 | +
|
| 72 | +For Facebook sign in support, follow step 3 and 4 of |
| 73 | +[Facebook login documentation](https://developers.google.com/firebase/docs/auth/ios/facebook-login#before_you_begin) |
| 74 | +, and add custom URL schemes following step 5 of [Facebook SDK for iOS-Getting started documentation](https://developers.facebook.com/docs/ios/getting-started). |
| 75 | +
|
| 76 | +Finally add a call to handle the URL that your application receives at the end of the |
| 77 | +Google/Facebook authentication process. |
| 78 | +
|
| 79 | +```objective |
| 80 | +- (BOOL)application:(UIApplication *)application |
| 81 | + openURL:(NSURL *)url |
| 82 | + sourceApplication:(NSString *)sourceApplication |
| 83 | + annotation:(id)annotation { |
| 84 | + return [[FIRAuthUI authUI] handleOpenURL:url sourceApplication:sourceApplication] |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | +### Sign In |
| 89 | + |
| 90 | +To start the authentication flow, obtain an `authViewController` instance from |
| 91 | +`FIRAuthUI`. In order to leverage FirebaseUI for iOS you must display the |
| 92 | +`authViewController`; you can present it as the first view controller of your |
| 93 | +app or present it from another view controller within your app. In order to |
| 94 | +present the `authViewController` obtain as instance as follows: |
| 95 | + |
| 96 | +```objective-c |
| 97 | +UIViewController *authViewController = [authUI authViewController]; |
| 98 | +// Use authViewController as your root view controller, |
| 99 | +// or present it on top of an existing view controller. |
| 100 | + |
| 101 | +- (void)authUI:(FIRAuthUI *)authUI |
| 102 | + didSignInWithUser:(nullable FIRUser *)user |
| 103 | + error:(nullable NSError *)error { |
| 104 | + // Implement this method to handle signed in user or error if any. |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +## Customizing FirebaseUI for authentication |
| 109 | +### Terms of Service (ToS) URL customization: |
| 110 | + |
| 111 | +The Terms of Service URL for your application, which is displayed on the |
| 112 | +email/password account creation screen, can be specified as follows: |
| 113 | +```objective-c |
| 114 | +authUI.TOSURL = [NSURL URLWithString:@"http://example.com/tos"]; |
| 115 | +``` |
| 116 | +
|
| 117 | +### Custom strings |
| 118 | +
|
| 119 | +You can override the default messages and prompts shown to your users. This can |
| 120 | +be useful for things such as adding support for other languages besides English. |
| 121 | +
|
| 122 | +In order to do so: |
| 123 | +
|
| 124 | +```objective-c |
| 125 | +authUI.customStringsBundle = [NSBundle mainBundle]; // Or any custom bundle. |
| 126 | +``` |
| 127 | + |
| 128 | +The bundle should include [.strings](Auth/AuthUI/Strings/FirebaseAuthUI.strings) |
| 129 | +files that have the same names as the default files, namely `FirebaseAuthUI`, |
| 130 | +`FirebaseGoogleAuthUI`, and `FirebaseFacebookAuthUI`. Each string in these files |
| 131 | +should have the same key as its counterpart in the default `.strings` files. |
| 132 | + |
| 133 | +### Custom sign-in screen |
| 134 | + |
| 135 | +You can customize everything about the authentication method picker screen, |
| 136 | +except for the actual sign-in buttons. |
| 137 | + |
| 138 | +In order to do so, create a subclass of `FIRAuthPickerViewController` and |
| 139 | +customize it to your needs. Provide `FIRAuthUI` with an instance of your |
| 140 | +subclass by implementing the delegate method |
| 141 | +`authPickerViewControllerForAuthUI:` as follows: |
| 142 | + |
| 143 | +```objective-c |
| 144 | +- (FIRAuthPickerViewController *)authPickerViewControllerForAuthUI:(FIRAuthUI *)authUI { |
| 145 | + return [[YourCustomAuthPickerViewController alloc] initWithAuthUI:authUI]; |
| 146 | +} |
| 147 | +``` |
0 commit comments