Configuration
All operations, callbacks, UI customizations are done through an FUIAuth
instance. The FUIAuth
instance associated with the default Firebase Auth
instance can be accessed as follows:
// Swift
import FirebaseUI
/* ... */
FirebaseApp.configure()
let authUI = FUIAuth.defaultAuthUI()
// You need to adopt a FUIAuthDelegate protocol to receive callback
authUI?.delegate = self
// Objective-C
@import FirebaseUI;
/* ... */
[FIRApp configure];
FUIAuth *authUI = [FUIAuth defaultAuthUI];
// You need to adopt a FUIAuthDelegate protocol to receive callback
authUI.delegate = self;
This instance can then be configured with the providers you wish to support:
// Swift
import FirebaseUI
/* ... */
let providers: [FUIAuthProvider] = [
FUIEmailAuth(),
FUIGoogleAuth(),
FUIFacebookAuth(),
FUIPhoneAuth(authUI: FUIAuth.defaultAuthUI()),
FUIOAuth.appleAuthProvider(),
FUIOAuth.twitterAuthProvider(),
FUIOAuth.githubAuthProvider(),
FUIOAuth.microsoftAuthProvider(),
FUIOAuth.yahooAuthProvider(),
]
authUI?.providers = providers
// Objective-C
@import FirebaseUI;
/* ... */
NSArray<id<FUIAuthProvider>> *providers = @[
[[FUIEmailAuth alloc] init],
[[FUIGoogleAuth alloc] init],
[[FUIFacebookAuth alloc] init],
[[FUIPhoneAuth alloc] initWithAuthUI:[FUIAuth defaultAuthUI]],
[FUIOAuth appleAuthProvider],
[FUIOAuth twitterAuthProvider],
[FUIOAuth githubAuthProvider],
[FUIOAuth microsoftAuthProvider],
[FUIOAuth yahooAuthProvider]
];
self.authUI.providers = providers;
For Google Sign-in support, add custom URL schemes to your Xcode project
(step 1 of the implement Google Sign-In documentation).
For Sign in with Apple support, add the Sign in with Apple capability to your entitlements file.
For Facebook Login support, follow step 3 and 4 of
Facebook login documentation,
and follow the Facebook SDK for iOS Getting started documentation.
Finally, add a call to handle the URL that your application receives at the end
of the Google/Facebook authentication process.
// Swift
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String?
if FUIAuth.defaultAuthUI()?.handleOpen(url, sourceApplication: sourceApplication) ?? false {
return true
}
// other URL handling goes here.
return false
}
// Objective-C
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary *)options {
NSString *sourceApplication = options[UIApplicationOpenURLOptionsSourceApplicationKey];
return [[FUIAuth defaultAuthUI] handleOpenURL:url sourceApplication:sourceApplication];
}
Sign In
To start the authentication flow, obtain an authViewController
instance from
FUIAuth
. In order to leverage FirebaseUI for iOS you must display the
authViewController
; you can present it as the first view controller of your
app or present it from another view controller within your app. In order to
present the authViewController
obtain as instance as follows:
// Swift
// Present the auth view controller and then implement the sign in callback.
let authViewController = authUI!.authViewController()
func authUI(_ authUI: FUIAuth, didSignInWithAuthDataResult authDataResult: AuthDataResult?, error: Error?) {
// handle user (`authDataResult.user`) and error as necessary
}
// Objective-C
UINavigationController *authViewController = [authUI authViewController];
// Use authViewController as your root view controller,
// or present it on top of an existing view controller.
- (void)authUI:(FUIAuth *)authUI
didSignInWithAuthDataResult:(nullable FIRAuthDataResult *)authDataResult
error:(nullable NSError *)error {
// Implement this method to handle signed in user (`authDataResult.user`) or error if any.
}
Configuring Email Link Sign In
To use email link sign in, you will first need to enable it in the Firebase Console. Additionally, you will also have to enable Firebase Dynamic Links.
You can enable email link sign in by initializing an FUIEmailAuth
instance with FIREmailLinkAuthSignInMethod
. You will also need to provide a valid FIRActionCodeSettings
object with handleCodeInApp
set to true. Additionally, you need to whitelist the URL you pass to the iniatializer; you can do so in the Firebase Console (Authentication -> Sign in Methods -> Authorized domains).
// Objective-C
FIRActionCodeSettings *actionCodeSettings = [[FIRActionCodeSettings alloc] init];
actionCodeSettings.URL = [NSURL URLWithString:@"https://example.appspot.com"];
actionCodeSettings.handleCodeInApp = YES;
[actionCodeSettings setAndroidPackageName:@"com.firebase.example"
installIfNotAvailable:NO
minimumVersion:@"12"];
// Swift
var actionCodeSettings = ActionCodeSettings()
actionCodeSettings.url = URL(string: "https://example.appspot.com")
actionCodeSettings.handleCodeInApp = true
actionCodeSettings.setAndroidPackageName("com.firebase.example", installIfNotAvailable: false, minimumVersion: "12")
Once you catch the deep link, you will need to pass it to the auth UI so it can be handled.
// Objective-C
[FUIAuth.defaultAuthUI handleOpenURL:url sourceApplication:sourceApplication];
// Swift
Auth.defaultAuthUI.handleOpenURL(url, sourceApplication: sourceApplication)
We support cross device email link sign in for the normal flows. It is not supported with anonymous user upgrade. By default, cross device support is enabled. You can disable it setting forceSameDevice
to false in the FUIEmailAuth
initializer.