Skip to content

Commit e49d6c2

Browse files
docs: getting started on android FirebaseUI v10
1 parent c5461b6 commit e49d6c2

1 file changed

Lines changed: 268 additions & 0 deletions

File tree

GETTING_STARTED.md

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
# FirebaseUI Auth for Android
2+
3+
FirebaseUI Auth is a modern, Compose-based authentication library for Firebase Authentication on Android.
4+
5+
`10.x` is currently a beta release.
6+
7+
If you used the older FirebaseUI Auth guides, the biggest change in `10.x` is that the recommended sign-in flow now uses Compose screens instead of `Intent` builders and `ActivityResultLauncher` callbacks.
8+
9+
FirebaseUI Auth provides the following benefits:
10+
11+
- Credential Manager integration for faster sign-in on Android.
12+
- Material 3 UI that can inherit your app theme.
13+
- Multiple authentication providers, including email/password, phone, Google, Facebook, Apple, GitHub, Microsoft, Yahoo, Twitter, anonymous auth, and custom OAuth.
14+
- Multi-factor authentication support, including SMS and TOTP.
15+
- Built-in flows for account management, account linking, and anonymous user upgrade.
16+
17+
## Before you begin
18+
19+
1. [Add Firebase to your Android project](https://firebase.google.com/docs/android/setup).
20+
2. Make sure your app is set up for Jetpack Compose.
21+
3. In the [Firebase console](https://console.firebase.google.com/), enable the sign-in methods you want to support.
22+
23+
Add FirebaseUI Auth to your app module:
24+
25+
```kotlin
26+
dependencies {
27+
implementation("com.firebaseui:firebase-ui-auth:10.0.0-beta02")
28+
29+
// Most apps also declare Firebase and Compose dependencies directly.
30+
implementation(platform("com.google.firebase:firebase-bom:<latest-version>"))
31+
implementation("com.google.firebase:firebase-auth")
32+
33+
implementation(platform("androidx.compose:compose-bom:<latest-version>"))
34+
implementation("androidx.compose.material3:material3")
35+
36+
// Required only if Facebook Login support is needed
37+
implementation("com.facebook.android:facebook-login:<latest-version>")
38+
}
39+
```
40+
41+
The high-level FirebaseUI Auth API is Compose-based, so if your app is not already using Compose you will need to enable it first.
42+
43+
## Provider configuration
44+
45+
Some providers need additional setup before you can sign users in.
46+
47+
### Google Sign-In
48+
49+
- Enable Google in the Firebase console.
50+
- Add your app's SHA fingerprint in Firebase.
51+
- Download the updated `google-services.json`.
52+
- `AuthProvider.Google(..., serverClientId = null)` can use the `default_web_client_id` generated by the `google-services` Gradle plugin.
53+
54+
### Facebook Login
55+
56+
If you support Facebook Login, add these values to `strings.xml`:
57+
58+
```xml
59+
<resources>
60+
<string name="facebook_application_id" translatable="false">YOUR_FACEBOOK_APP_ID</string>
61+
<string name="facebook_login_protocol_scheme" translatable="false">fbYOUR_FACEBOOK_APP_ID</string>
62+
<string name="facebook_client_token" translatable="false">YOUR_FACEBOOK_CLIENT_TOKEN</string>
63+
</resources>
64+
```
65+
66+
### Other providers
67+
68+
Apple, GitHub, Microsoft, Yahoo, Twitter, and custom OAuth providers are configured in Firebase Authentication. Most of them do not require extra Android-specific resources.
69+
70+
## Sign in
71+
72+
Create an `AuthUIConfiguration`, then show `FirebaseAuthScreen`.
73+
74+
```kotlin
75+
class MainActivity : ComponentActivity() {
76+
override fun onCreate(savedInstanceState: Bundle?) {
77+
super.onCreate(savedInstanceState)
78+
79+
val authUI = FirebaseAuthUI.getInstance()
80+
81+
setContent {
82+
MyAppTheme {
83+
val configuration = authUIConfiguration {
84+
context = applicationContext
85+
theme = AuthUITheme.fromMaterialTheme()
86+
providers {
87+
provider(AuthProvider.Email())
88+
provider(
89+
AuthProvider.Google(
90+
scopes = listOf("email"),
91+
serverClientId = null,
92+
)
93+
)
94+
}
95+
}
96+
97+
if (authUI.isSignedIn()) {
98+
HomeScreen()
99+
} else {
100+
FirebaseAuthScreen(
101+
configuration = configuration,
102+
authUI = authUI,
103+
onSignInSuccess = { result ->
104+
// User signed in successfully
105+
},
106+
onSignInFailure = { exception ->
107+
// Sign in failed
108+
},
109+
onSignInCancelled = {
110+
finish()
111+
},
112+
)
113+
}
114+
}
115+
}
116+
}
117+
}
118+
```
119+
120+
This gives you a complete authentication flow with:
121+
122+
- Email/password sign-in and sign-up.
123+
- Google Sign-In.
124+
- Password reset.
125+
- Material 3 styling.
126+
- Credential Manager support.
127+
- Error handling through direct callbacks.
128+
129+
## Configure providers
130+
131+
Choose the providers you want inside `authUIConfiguration`:
132+
133+
```kotlin
134+
val configuration = authUIConfiguration {
135+
context = applicationContext
136+
providers {
137+
provider(AuthProvider.Email())
138+
provider(
139+
AuthProvider.Phone(
140+
defaultCountryCode = "US",
141+
)
142+
)
143+
provider(
144+
AuthProvider.Google(
145+
scopes = listOf("email"),
146+
serverClientId = null,
147+
)
148+
)
149+
provider(AuthProvider.Facebook())
150+
}
151+
}
152+
```
153+
154+
### Email link sign-in
155+
156+
Email link sign-in now lives in the email provider configuration:
157+
158+
```kotlin
159+
val configuration = authUIConfiguration {
160+
context = applicationContext
161+
providers {
162+
provider(
163+
AuthProvider.Email(
164+
isEmailLinkSignInEnabled = true,
165+
emailLinkActionCodeSettings = actionCodeSettings {
166+
url = "https://example.com/auth"
167+
handleCodeInApp = true
168+
setAndroidPackageName(
169+
"com.example.app",
170+
true,
171+
null,
172+
)
173+
},
174+
)
175+
)
176+
}
177+
}
178+
```
179+
180+
For the full deep-link handling flow, see `auth/README.md`.
181+
182+
## Sign out
183+
184+
FirebaseUI Auth provides convenience methods for sign-out and account deletion:
185+
186+
```kotlin
187+
lifecycleScope.launch {
188+
FirebaseAuthUI.getInstance().signOut(applicationContext)
189+
}
190+
```
191+
192+
```kotlin
193+
lifecycleScope.launch {
194+
FirebaseAuthUI.getInstance().delete(applicationContext)
195+
}
196+
```
197+
198+
## Customization
199+
200+
FirebaseUI Auth is much more customizable in `10.x`, but the simplest way to get started is to set a theme directly in `authUIConfiguration`:
201+
202+
```kotlin
203+
val configuration = authUIConfiguration {
204+
context = applicationContext
205+
providers {
206+
provider(AuthProvider.Email())
207+
provider(AuthProvider.Google(scopes = listOf("email"), serverClientId = null))
208+
}
209+
theme = AuthUITheme.Adaptive
210+
}
211+
```
212+
213+
You can also:
214+
215+
- Use `AuthUITheme.Default`, `AuthUITheme.DefaultDark`, or `AuthUITheme.Adaptive`.
216+
- Inherit your app theme with `AuthUITheme.fromMaterialTheme()`.
217+
- Customize the default theme with `.copy()`.
218+
- Build a fully custom `AuthUITheme`.
219+
- Set a logo, Terms of Service URL, and Privacy Policy URL in `authUIConfiguration`.
220+
221+
For full theming and customization details, including theme precedence, provider button styling, and custom themes, see `auth/README.md`.
222+
223+
## Existing Activity-based apps
224+
225+
If your app still uses Activities and the Activity Result API, you can keep an Activity-based launch flow by using `AuthFlowController`:
226+
227+
```kotlin
228+
private val authLauncher = registerForActivityResult(
229+
ActivityResultContracts.StartActivityForResult(),
230+
) { result ->
231+
if (result.resultCode == RESULT_OK) {
232+
val user = FirebaseAuth.getInstance().currentUser
233+
// ...
234+
} else {
235+
// User cancelled or sign-in failed
236+
}
237+
}
238+
239+
val configuration = authUIConfiguration {
240+
context = applicationContext
241+
providers {
242+
provider(AuthProvider.Email())
243+
provider(
244+
AuthProvider.Google(
245+
scopes = listOf("email"),
246+
serverClientId = null,
247+
)
248+
)
249+
}
250+
}
251+
252+
val controller = FirebaseAuthUI.getInstance().createAuthFlow(configuration)
253+
authLauncher.launch(controller.createIntent(this))
254+
```
255+
256+
This is the closest match to the old FirebaseUI Auth mental model, but the Compose `FirebaseAuthScreen` API is the recommended starting point for new integrations.
257+
258+
## Migrating from the old FirebaseUI Auth flow
259+
260+
If you are coming from `9.x` or the older Firebase documentation:
261+
262+
- `AuthUI.getInstance().createSignInIntentBuilder()` becomes `authUIConfiguration {}` plus `FirebaseAuthScreen`.
263+
- `AuthUI.IdpConfig.*Builder()` becomes `AuthProvider.*`.
264+
- XML-based FirebaseUI theme resources become `AuthUITheme`.
265+
- `ActivityResultLauncher` result parsing becomes direct success, failure, and cancel callbacks.
266+
- Activity-based flows are still possible through `AuthFlowController`.
267+
268+
For a complete migration guide, see `auth/README.md` and `docs/upgrade-to-10.0.md`.

0 commit comments

Comments
 (0)