Skip to content

Commit a62097d

Browse files
committed
feat(AuthUIConfiguration): implement configuration model, DSL builder and tests
1 parent 1e44a13 commit a62097d

File tree

8 files changed

+915
-3
lines changed

8 files changed

+915
-3
lines changed

auth/build.gradle.kts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44
id("com.android.library")
55
id("com.vanniktech.maven.publish")
66
id("org.jetbrains.kotlin.android")
7+
id("org.jetbrains.kotlin.plugin.compose") version "2.0.0"
78
}
89

910
android {
@@ -67,9 +68,20 @@ android {
6768
kotlinOptions {
6869
jvmTarget = "17"
6970
}
71+
buildFeatures {
72+
compose = true
73+
}
7074
}
7175

7276
dependencies {
77+
implementation(platform(Config.Libs.Androidx.Compose.bom))
78+
implementation(Config.Libs.Androidx.Compose.ui)
79+
implementation(Config.Libs.Androidx.Compose.uiGraphics)
80+
implementation(Config.Libs.Androidx.Compose.material3)
81+
implementation(Config.Libs.Androidx.Compose.foundation)
82+
implementation(Config.Libs.Androidx.Compose.tooling)
83+
implementation(Config.Libs.Androidx.Compose.toolingPreview)
84+
implementation(Config.Libs.Androidx.Compose.activityCompose)
7385
implementation(Config.Libs.Androidx.materialDesign)
7486
implementation(Config.Libs.Androidx.activity)
7587
// The new activity result APIs force us to include Fragment 1.3.0
@@ -101,6 +113,7 @@ dependencies {
101113
testImplementation(Config.Libs.Test.mockito)
102114
testImplementation(Config.Libs.Test.core)
103115
testImplementation(Config.Libs.Test.robolectric)
116+
testImplementation(Config.Libs.Test.kotlinReflect)
104117
testImplementation(Config.Libs.Provider.facebook)
105118

106119
debugImplementation(project(":internal:lintchecks"))
Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
1+
/*
2+
* Copyright 2025 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the
10+
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
* express or implied. See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.firebase.ui.auth.compose.configuration
16+
17+
import android.graphics.Color
18+
import androidx.compose.ui.graphics.vector.ImageVector
19+
import com.google.firebase.auth.ActionCodeSettings
20+
21+
@AuthUIConfigurationDsl
22+
class AuthProvidersBuilder {
23+
private val providers = mutableListOf<AuthProvider>()
24+
25+
fun provider(provider: AuthProvider) {
26+
providers.add(provider)
27+
}
28+
29+
internal fun build(): List<AuthProvider> = providers.toList()
30+
}
31+
32+
/**
33+
* Base sealed class for authentication providers.
34+
*/
35+
sealed class AuthProvider() {
36+
/**
37+
* Email/Password authentication provider configuration.
38+
*/
39+
data class Email(
40+
/**
41+
* Requires the user to provide a display name. Defaults to true.
42+
*/
43+
val requireDisplayName: Boolean = true,
44+
45+
/**
46+
* Enables email link sign-in, Defaults to false.
47+
*/
48+
val enableEmailLinkSignIn: Boolean = false,
49+
50+
/**
51+
* Settings for email link actions.
52+
*/
53+
val actionCodeSettings: ActionCodeSettings?,
54+
55+
/**
56+
* Allows new accounts to be created. Defaults to true.
57+
*/
58+
val allowNewAccounts: Boolean = true,
59+
60+
/**
61+
* The minimum length for a password. Defaults to 6.
62+
*/
63+
val minimumPasswordLength: Int = 6,
64+
65+
/**
66+
* A list of custom password validation rules.
67+
*/
68+
val passwordValidationRules: List<PasswordRule>
69+
) : AuthProvider()
70+
71+
/**
72+
* Phone number authentication provider configuration.
73+
*/
74+
data class Phone(
75+
/**
76+
* The default country code to pre-select.
77+
*/
78+
val defaultCountryCode: String?,
79+
80+
/**
81+
* A list of allowed country codes.
82+
*/
83+
val allowedCountries: List<String>?,
84+
85+
/**
86+
* The expected length of the SMS verification code. Defaults to 6.
87+
*/
88+
val smsCodeLength: Int = 6,
89+
90+
/**
91+
* The timeout in seconds for receiving the SMS. Defaults to 60L.
92+
*/
93+
val timeout: Long = 60L,
94+
95+
/**
96+
* Enables instant verification of the phone number. Defaults to true.
97+
*/
98+
val enableInstantVerification: Boolean = true,
99+
100+
/**
101+
* Enables automatic retrieval of the SMS code. Defaults to true.
102+
*/
103+
val enableAutoRetrieval: Boolean = true
104+
) : AuthProvider()
105+
106+
/**
107+
* Google Sign-In provider configuration.
108+
*/
109+
data class Google(
110+
/**
111+
* The list of scopes to request.
112+
*/
113+
val scopes: List<String>,
114+
115+
/**
116+
* The OAuth 2.0 client ID for your server.
117+
*/
118+
val serverClientId: String?,
119+
120+
/**
121+
* Requests an ID token. Default to true.
122+
*/
123+
val requestIdToken: Boolean = true,
124+
125+
/**
126+
* Requests the user's profile information. Defaults to true.
127+
*/
128+
val requestProfile: Boolean = true,
129+
130+
/**
131+
* Requests the user's email address. Defaults to true.
132+
*/
133+
val requestEmail: Boolean = true
134+
) : AuthProvider()
135+
136+
/**
137+
* Facebook Login provider configuration.
138+
*/
139+
data class Facebook(
140+
/**
141+
* The list of scopes (permissions) to request. Defaults to email and public_profile.
142+
*/
143+
val scopes: List<String> = listOf("email", "public_profile"),
144+
145+
/**
146+
* if true, enable limited login mode. Defaults to false.
147+
*/
148+
val limitedLogin: Boolean = false
149+
) : AuthProvider()
150+
151+
/**
152+
* Twitter/X authentication provider configuration.
153+
*/
154+
data class Twitter(
155+
/**
156+
* A map of custom OAuth parameters.
157+
*/
158+
val customParameters: Map<String, String>
159+
) : AuthProvider()
160+
161+
/**
162+
* Github authentication provider configuration.
163+
*/
164+
data class Github(
165+
/**
166+
* The list of scopes to request. Defaults to user:email.
167+
*/
168+
val scopes: List<String> = listOf("user:email"),
169+
170+
/**
171+
* A map of custom OAuth parameters.
172+
*/
173+
val customParameters: Map<String, String>
174+
) : AuthProvider()
175+
176+
/**
177+
* Microsoft authentication provider configuration.
178+
*/
179+
data class Microsoft(
180+
/**
181+
* The list of scopes to request. Defaults to openid, profile, email.
182+
*/
183+
val scopes: List<String> = listOf("openid", "profile", "email"),
184+
185+
/**
186+
* The tenant ID for Azure Active Directory.
187+
*/
188+
val tenant: String?,
189+
190+
/**
191+
* A map of custom OAuth parameters.
192+
*/
193+
val customParameters: Map<String, String>
194+
) : AuthProvider()
195+
196+
/**
197+
* Yahoo authentication provider configuration.
198+
*/
199+
data class Yahoo(
200+
/**
201+
* The list of scopes to request. Defaults to openid, profile, email.
202+
*/
203+
val scopes: List<String> = listOf("openid", "profile", "email"),
204+
205+
/**
206+
* A map of custom OAuth parameters.
207+
*/
208+
val customParameters: Map<String, String>
209+
) : AuthProvider()
210+
211+
/**
212+
* Apple Sign-In provider configuration.
213+
*/
214+
data class Apple(
215+
/**
216+
* The list of scopes to request. Defaults to name and email.
217+
*/
218+
val scopes: List<String> = listOf("name", "email"),
219+
220+
/**
221+
* The locale for the sign-in page.
222+
*/
223+
val locale: String?,
224+
225+
/**
226+
* A map of custom OAuth parameters.
227+
*/
228+
val customParameters: Map<String, String>
229+
) : AuthProvider()
230+
231+
/**
232+
* Anonymous authentication provider. It has no configurable properties.
233+
*/
234+
object Anonymous : AuthProvider()
235+
236+
/**
237+
* A generic OAuth provider for any unsupported provider.
238+
*/
239+
data class GenericOAuth(
240+
/**
241+
* The provider ID as configured in the Firebase console.
242+
*/
243+
val providerId: String,
244+
245+
/**
246+
* The list of scopes to request.
247+
*/
248+
val scopes: List<String>,
249+
250+
/**
251+
* A map of custom OAuth parameters.
252+
*/
253+
val customParameters: Map<String, String>,
254+
255+
/**
256+
* The text to display on the provider button.
257+
*/
258+
val buttonLabel: String,
259+
260+
/**
261+
* An optional icon for the provider button.
262+
*/
263+
val buttonIcon: ImageVector?,
264+
265+
/**
266+
* An optional background color for the provider button.
267+
*/
268+
val buttonColor: Color?
269+
) : AuthProvider()
270+
}

0 commit comments

Comments
 (0)