-
Notifications
You must be signed in to change notification settings - Fork 1.9k
docs: getting started on android FirebaseUI v10 #2309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
russellwheatley
wants to merge
12
commits into
master
Choose a base branch
from
getting-started-docs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+246
−1
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e49d6c2
docs: getting started on android FirebaseUI v10
russellwheatley 3bd98f4
docs: write were latest version of firebase auth can be found
russellwheatley b4e880a
docs: update jetpack compose version and link to docs
russellwheatley 9471088
docs: add link to apps still using activities
russellwheatley a530e83
Apply suggestions from code review
russellwheatley 24c0c3e
docs: update before you begin list
russellwheatley 928d2e5
docs: remove jetpack compose dependencies from snippet
russellwheatley 8a77bf4
docs: scrub mention of compose
russellwheatley bd44462
docs: update provider links to help setup for firebase auth
russellwheatley 974efc1
docs: remove mention of old firebaseui android
russellwheatley 61b78f1
docs: get headers to match ios and web platforms
russellwheatley 37e0722
docs(GETTING_STARTED): adopt feedback
mikehardy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,243 @@ | ||
| # Easily add sign-in to your Android app with FirebaseUI | ||
|
|
||
| [FirebaseUI](https://github.com/firebase/firebaseui-android) Auth is a library built on top of the Firebase Authentication SDK that provides drop-in UI flows for use in your app. | ||
|
|
||
| Caution: Version 10.x is currently a **beta release**. This means that the functionality might change in backward-incompatible ways or have limited support. A beta release is not subject to any SLA or deprecation policy. | ||
|
|
||
| The recommended sign-in flow uses Compose screens. For apps that still use Activities, see the [Existing Activity-based apps](#existing-activity-based-apps) section. | ||
|
|
||
| FirebaseUI Auth provides the following benefits: | ||
|
|
||
| - **Multiple Providers** — sign-in flows for email/password, phone, Google, Facebook, Apple, GitHub, Microsoft, Yahoo, Twitter, anonymous auth, and custom OAuth. | ||
| - **Account Management** — flows to handle account management tasks, such as account creation and password resets. | ||
| - **Account Linking** — flows to safely link user accounts across identity providers. | ||
| - **Anonymous User Upgrading** — flows to safely upgrade anonymous users. | ||
| - **Custom Themes** — Material 3 UI support that can inherit your app theme. Also, because FirebaseUI is open source, you can fork the project and customize it exactly to your needs. | ||
| - **Credential Manager** — automatic integration with [Credential Manager](https://developer.android.com/identity/sign-in/credential-manager) for fast cross-device sign-in. | ||
| - **Multi-Factor Authentication** — SMS and TOTP support for additional security. | ||
|
|
||
| ## Before you begin | ||
|
|
||
| 1. If you haven't already, [add Firebase to your Android project](https://firebase.google.com/docs/android/setup). | ||
| 2. In the [Firebase console](https://console.firebase.google.com/), enable the sign-in methods you want to support. | ||
| 3. Add FirebaseUI Auth to your app module: | ||
|
|
||
| ```kotlin | ||
| dependencies { | ||
| // Check Maven Central for the latest version: | ||
| // https://central.sonatype.com/artifact/com.firebaseui/firebase-ui-auth/versions | ||
| implementation("com.firebaseui:firebase-ui-auth:10.0.0-beta02") | ||
|
|
||
| // Required only if Facebook login support is required | ||
| // Find the latest Facebook SDK releases here: https://goo.gl/Ce5L94 | ||
| implementation("com.facebook.android:facebook-android-sdk:8.x") | ||
| } | ||
| ``` | ||
|
|
||
| ## Set up sign-in methods | ||
|
|
||
| ### Google Sign-In | ||
|
|
||
| Google Sign-In configuration is automatically provided by the [google-services Gradle plugin](https://developers.google.com/android/guides/google-services-plugin). Ensure you have enabled Google Sign-In in the [Firebase Console](https://console.firebase.google.com/project/_/authentication/providers). | ||
|
|
||
| ### Facebook Login | ||
|
|
||
| If using Facebook Login, add your Facebook App ID to `strings.xml`: | ||
|
|
||
| ```xml | ||
| <resources> | ||
| <string name="facebook_application_id" translatable="false">YOUR_FACEBOOK_APP_ID</string> | ||
| <string name="facebook_login_protocol_scheme" translatable="false">fbYOUR_FACEBOOK_APP_ID</string> | ||
| <string name="facebook_client_token" translatable="false">CHANGE-ME</string> | ||
| </resources> | ||
| ``` | ||
|
|
||
| See the [Facebook for Developers](https://developers.facebook.com/) documentation for setup instructions. | ||
|
|
||
| ### Other Providers | ||
|
|
||
| Twitter, GitHub, Microsoft, Yahoo, and Apple providers require configuration in the Firebase Console but no additional Android-specific setup. See the [Firebase Auth documentation](https://firebase.google.com/docs/auth) for provider-specific instructions. | ||
|
|
||
| Choose the providers you want inside `authUIConfiguration`: | ||
|
|
||
| ```kotlin | ||
| val configuration = authUIConfiguration { | ||
| context = applicationContext | ||
| providers { | ||
| provider(AuthProvider.Email()) | ||
| provider( | ||
| AuthProvider.Phone( | ||
| defaultCountryCode = "US", | ||
| ) | ||
| ) | ||
| provider( | ||
| AuthProvider.Google( | ||
| scopes = listOf("email"), | ||
| serverClientId = null, | ||
| ) | ||
| ) | ||
| provider(AuthProvider.Facebook()) | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Email link sign-in | ||
|
|
||
| Email link sign-in lives in the email provider configuration: | ||
|
|
||
| ```kotlin | ||
| val configuration = authUIConfiguration { | ||
| context = applicationContext | ||
| providers { | ||
| provider( | ||
| AuthProvider.Email( | ||
| isEmailLinkSignInEnabled = true, | ||
| emailLinkActionCodeSettings = actionCodeSettings { | ||
| url = "https://example.com/auth" | ||
| handleCodeInApp = true | ||
| setAndroidPackageName( | ||
| "com.example.app", | ||
| true, | ||
| null, | ||
| ) | ||
| }, | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| For the full deep-link handling flow, see [the Email Link Sign-In section of the README in GitHub](https://github.com/firebase/FirebaseUI-Android/blob/master/auth/README.md#email-link-sign-in). | ||
|
|
||
| ## Sign in | ||
|
|
||
| Create an `AuthUIConfiguration`, then show `FirebaseAuthScreen`. | ||
|
|
||
| ```kotlin | ||
| class MainActivity : ComponentActivity() { | ||
| override fun onCreate(savedInstanceState: Bundle?) { | ||
| super.onCreate(savedInstanceState) | ||
|
|
||
| val authUI = FirebaseAuthUI.getInstance() | ||
|
|
||
| setContent { | ||
| MyAppTheme { | ||
| val configuration = authUIConfiguration { | ||
| context = applicationContext | ||
| theme = AuthUITheme.fromMaterialTheme() | ||
| providers { | ||
| provider(AuthProvider.Email()) | ||
| provider( | ||
| AuthProvider.Google( | ||
| scopes = listOf("email"), | ||
| serverClientId = null, | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| if (authUI.isSignedIn()) { | ||
| HomeScreen() | ||
| } else { | ||
| FirebaseAuthScreen( | ||
| configuration = configuration, | ||
| authUI = authUI, | ||
| onSignInSuccess = { result -> | ||
| // User signed in successfully | ||
| }, | ||
| onSignInFailure = { exception -> | ||
| // Sign in failed | ||
| }, | ||
| onSignInCancelled = { | ||
| finish() | ||
| }, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| This gives you a complete authentication flow with: | ||
|
|
||
| - Password Authentication. | ||
| - Google Sign-In. | ||
| - Password reset. | ||
| - Material 3 styling. | ||
| - Credential Manager support. | ||
| - Error handling through direct callbacks. | ||
|
|
||
| ## Sign out | ||
|
|
||
| FirebaseUI Auth provides convenience methods for sign-out and account deletion: | ||
|
|
||
| ```kotlin | ||
| lifecycleScope.launch { | ||
| FirebaseAuthUI.getInstance().signOut(applicationContext) | ||
| } | ||
| ``` | ||
|
|
||
| ```kotlin | ||
| lifecycleScope.launch { | ||
| FirebaseAuthUI.getInstance().delete(applicationContext) | ||
| } | ||
| ``` | ||
|
|
||
| ## Customization | ||
|
|
||
| FirebaseUI Auth is customizable, and the simplest way to get started is to set a theme directly in `authUIConfiguration`: | ||
|
|
||
| ```kotlin | ||
| val configuration = authUIConfiguration { | ||
| context = applicationContext | ||
| providers { | ||
| provider(AuthProvider.Email()) | ||
| provider(AuthProvider.Google(scopes = listOf("email"), serverClientId = null)) | ||
| } | ||
| theme = AuthUITheme.Adaptive | ||
| } | ||
| ``` | ||
|
|
||
| You can also: | ||
|
|
||
| - Use `AuthUITheme.Default`, `AuthUITheme.DefaultDark`, or `AuthUITheme.Adaptive`. | ||
| - Inherit your app theme with `AuthUITheme.fromMaterialTheme()`. | ||
| - Customize the default theme with `.copy()`. | ||
| - Build a fully custom `AuthUITheme`. | ||
| - Set a logo, Terms of Service URL, and Privacy Policy URL in `authUIConfiguration`. | ||
|
|
||
| For full theming and customization details, including theme precedence, provider button styling, and custom themes, see [the Theming and Customization section of the readme in GitHub](https://github.com/firebase/FirebaseUI-Android/blob/master/auth/README.md#theming--customization). | ||
|
|
||
| ## Existing Activity-based apps {#existing-activity-based-apps} | ||
|
|
||
| If your app still uses Activities and the Activity Result API, you can keep an Activity-based launch flow by using `AuthFlowController`: | ||
|
|
||
| ```kotlin | ||
| private val authLauncher = registerForActivityResult( | ||
| ActivityResultContracts.StartActivityForResult(), | ||
| ) { result -> | ||
| if (result.resultCode == RESULT_OK) { | ||
| val user = FirebaseAuth.getInstance().currentUser | ||
| // ... | ||
| } else { | ||
| // User cancelled or sign-in failed | ||
| } | ||
| } | ||
|
|
||
| val configuration = authUIConfiguration { | ||
| context = applicationContext | ||
| providers { | ||
| provider(AuthProvider.Email()) | ||
| provider( | ||
| AuthProvider.Google( | ||
| scopes = listOf("email"), | ||
| serverClientId = null, | ||
| ) | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| val controller = FirebaseAuthUI.getInstance().createAuthFlow(configuration) | ||
| authLauncher.launch(controller.createIntent(this)) | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.