Skip to content

Commit bc10ca9

Browse files
authored
fix: use isMfaEnabled configuration flag with disabled button state and tooltip (#2297)
* fix: initialize serverClientId to default_web_client_id in AuthProvider.Google - The `applicationId` parameter has been removed from the `AuthProvider.Facebook` constructor. Configuration values (`facebook_application_id`, `facebook_login_protocol_scheme`, and `facebook_client_token`) are now exclusively read from `strings.xml`. - The `serverClientId` for the Google provider is now automatically populated from `R.string.default_web_client_id` if it is not explicitly provided. - Added validation to ensure `facebook_client_token` and `facebook_login_protocol_scheme` are configured in `strings.xml`. - Updated tests to use resource files for provider configuration instead of constructor arguments. - Updated `README.md` to reflect the new configuration requirements, including adding `facebook_client_token`. * fix: fallback to all Google accounts if no authorized accounts found during sign-in - Add filterByAuthorizedAccounts and autoSelectEnabled properties to AuthProvider.Google * fix: disable Manage MFA button and show tooltip when MFA is disabled * fix: implement MFA configuration disabled state with tooltip and expose configuration to custom authenticated content * fix CI * test: ignore flaky onManageMfa test due to CI timing issues
1 parent 52d3fe7 commit bc10ca9

File tree

90 files changed

+389
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+389
-5
lines changed

app/src/main/java/com/firebaseui/android/demo/HighLevelApiDemoActivity.kt

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ import androidx.compose.foundation.layout.fillMaxSize
1414
import androidx.compose.foundation.layout.height
1515
import androidx.compose.material3.Button
1616
import androidx.compose.material3.CircularProgressIndicator
17+
import androidx.compose.material3.ExperimentalMaterial3Api
1718
import androidx.compose.material3.MaterialTheme
19+
import androidx.compose.material3.PlainTooltip
1820
import androidx.compose.material3.ShapeDefaults
1921
import androidx.compose.material3.Surface
2022
import androidx.compose.material3.Text
23+
import androidx.compose.material3.TooltipAnchorPosition
24+
import androidx.compose.material3.TooltipBox
25+
import androidx.compose.material3.TooltipDefaults
26+
import androidx.compose.material3.rememberTooltipState
2127
import androidx.compose.runtime.Composable
2228
import androidx.compose.ui.Alignment
2329
import androidx.compose.ui.Modifier
@@ -57,6 +63,7 @@ class HighLevelApiDemoActivity : ComponentActivity() {
5763
tosUrl = "https://policies.google.com/terms"
5864
privacyPolicyUrl = "https://policies.google.com/privacy"
5965
isAnonymousUpgradeEnabled = false
66+
isMfaEnabled = false
6067
transitions = AuthUITransitions(
6168
enterTransition = { slideInHorizontally { it } },
6269
exitTransition = { slideOutHorizontally { -it } },
@@ -193,12 +200,14 @@ class HighLevelApiDemoActivity : ComponentActivity() {
193200
}
194201
}
195202

203+
@OptIn(ExperimentalMaterial3Api::class)
196204
@Composable
197205
private fun AppAuthenticatedContent(
198206
state: AuthState,
199207
uiContext: AuthSuccessUiContext
200208
) {
201209
val stringProvider = uiContext.stringProvider
210+
val configuration = uiContext.configuration
202211
when (state) {
203212
is AuthState.Success -> {
204213
val user = uiContext.authUI.getCurrentUser()
@@ -226,8 +235,25 @@ private fun AppAuthenticatedContent(
226235
textAlign = TextAlign.Center
227236
)
228237
Spacer(modifier = Modifier.height(16.dp))
229-
Button(onClick = uiContext.onManageMfa) {
230-
Text(stringProvider.manageMfaAction)
238+
TooltipBox(
239+
positionProvider = TooltipDefaults.rememberTooltipPositionProvider(
240+
TooltipAnchorPosition.Above
241+
),
242+
tooltip = {
243+
PlainTooltip {
244+
Text(stringProvider.mfaDisabledTooltip)
245+
}
246+
},
247+
state = rememberTooltipState(
248+
initialIsVisible = !configuration.isMfaEnabled
249+
)
250+
) {
251+
Button(
252+
onClick = uiContext.onManageMfa,
253+
enabled = configuration.isMfaEnabled
254+
) {
255+
Text(stringProvider.manageMfaAction)
256+
}
231257
}
232258
Spacer(modifier = Modifier.height(8.dp))
233259
Button(onClick = uiContext.onSignOut) {

auth/src/main/java/com/firebase/ui/auth/configuration/string_provider/AuthUIStringProvider.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,4 +539,7 @@ interface AuthUIStringProvider {
539539

540540
/** Tooltip message shown when new account sign-up is disabled */
541541
val newAccountsDisabledTooltip: String
542+
543+
/** Tooltip message shown when MFA is disabled */
544+
val mfaDisabledTooltip: String
542545
}

auth/src/main/java/com/firebase/ui/auth/configuration/string_provider/DefaultAuthUIStringProvider.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,4 +491,7 @@ class DefaultAuthUIStringProvider(
491491

492492
override val newAccountsDisabledTooltip: String
493493
get() = localizedContext.getString(R.string.fui_new_accounts_disabled_tooltip)
494+
495+
override val mfaDisabledTooltip: String
496+
get() = localizedContext.getString(R.string.fui_mfa_disabled_tooltip)
494497
}

auth/src/main/java/com/firebase/ui/auth/ui/screens/FirebaseAuthScreen.kt

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,16 @@ import androidx.compose.foundation.layout.padding
2828
import androidx.compose.material3.AlertDialog
2929
import androidx.compose.material3.Button
3030
import androidx.compose.material3.CircularProgressIndicator
31+
import androidx.compose.material3.ExperimentalMaterial3Api
3132
import androidx.compose.material3.MaterialTheme
33+
import androidx.compose.material3.PlainTooltip
3234
import androidx.compose.material3.Scaffold
3335
import androidx.compose.material3.Surface
3436
import androidx.compose.material3.Text
37+
import androidx.compose.material3.TooltipAnchorPosition
38+
import androidx.compose.material3.TooltipBox
39+
import androidx.compose.material3.TooltipDefaults
40+
import androidx.compose.material3.rememberTooltipState
3541
import androidx.compose.runtime.Composable
3642
import androidx.compose.runtime.CompositionLocalProvider
3743
import androidx.compose.runtime.LaunchedEffect
@@ -348,6 +354,7 @@ fun FirebaseAuthScreen(
348354
AuthSuccessUiContext(
349355
authUI = authUI,
350356
stringProvider = stringProvider,
357+
configuration = configuration,
351358
onSignOut = {
352359
coroutineScope.launch {
353360
try {
@@ -362,7 +369,15 @@ fun FirebaseAuthScreen(
362369
}
363370
},
364371
onManageMfa = {
365-
navController.navigate(AuthRoute.MfaEnrollment.route)
372+
if (configuration.isMfaEnabled) {
373+
navController.navigate(AuthRoute.MfaEnrollment.route)
374+
} else {
375+
val exception = AuthException.AuthCancelledException(
376+
message = "Multi-factor authentication is disabled in the configuration. " +
377+
"Enable MFA in AuthUIConfiguration to use this feature."
378+
)
379+
authUI.updateAuthState(AuthState.Error(exception))
380+
}
366381
},
367382
onReloadUser = {
368383
coroutineScope.launch {
@@ -410,6 +425,7 @@ fun FirebaseAuthScreen(
410425
SuccessDestination(
411426
authState = authState,
412427
stringProvider = stringProvider,
428+
configuration = configuration,
413429
uiContext = uiContext
414430
)
415431
}
@@ -654,6 +670,7 @@ sealed class AuthRoute(val route: String) {
654670
data class AuthSuccessUiContext(
655671
val authUI: FirebaseAuthUI,
656672
val stringProvider: AuthUIStringProvider,
673+
val configuration: AuthUIConfiguration,
657674
val onSignOut: () -> Unit,
658675
val onManageMfa: () -> Unit,
659676
val onReloadUser: () -> Unit,
@@ -664,13 +681,15 @@ data class AuthSuccessUiContext(
664681
private fun SuccessDestination(
665682
authState: AuthState,
666683
stringProvider: AuthUIStringProvider,
684+
configuration: AuthUIConfiguration,
667685
uiContext: AuthSuccessUiContext,
668686
) {
669687
when (authState) {
670688
is AuthState.Success -> {
671689
AuthSuccessContent(
672690
authUI = uiContext.authUI,
673691
stringProvider = stringProvider,
692+
configuration = configuration,
674693
onSignOut = uiContext.onSignOut,
675694
onManageMfa = uiContext.onManageMfa
676695
)
@@ -704,10 +723,12 @@ private fun SuccessDestination(
704723
}
705724
}
706725

726+
@OptIn(ExperimentalMaterial3Api::class)
707727
@Composable
708728
private fun AuthSuccessContent(
709729
authUI: FirebaseAuthUI,
710730
stringProvider: AuthUIStringProvider,
731+
configuration: AuthUIConfiguration,
711732
onSignOut: () -> Unit,
712733
onManageMfa: () -> Unit,
713734
) {
@@ -726,8 +747,25 @@ private fun AuthSuccessContent(
726747
Spacer(modifier = Modifier.height(16.dp))
727748
}
728749
if (user != null && authUI.auth.app.options.projectId != null) {
729-
Button(onClick = onManageMfa) {
730-
Text(stringProvider.manageMfaAction)
750+
TooltipBox(
751+
positionProvider = TooltipDefaults.rememberTooltipPositionProvider(
752+
TooltipAnchorPosition.Above
753+
),
754+
tooltip = {
755+
PlainTooltip {
756+
Text(stringProvider.mfaDisabledTooltip)
757+
}
758+
},
759+
state = rememberTooltipState(
760+
initialIsVisible = !configuration.isMfaEnabled
761+
)
762+
) {
763+
Button(
764+
onClick = onManageMfa,
765+
enabled = configuration.isMfaEnabled
766+
) {
767+
Text(stringProvider.manageMfaAction)
768+
}
731769
}
732770
Spacer(modifier = Modifier.height(8.dp))
733771
}

auth/src/main/res/values-ar/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,5 @@
179179

180180
<!-- Tooltips -->
181181
<string name="fui_new_accounts_disabled_tooltip" translation_description="Tooltip shown when sign-up button is disabled because new accounts are not allowed">This button is currently disabled because new accounts are not allowed</string>
182+
<string name="fui_mfa_disabled_tooltip" translation_description="Tooltip shown when manage MFA button is disabled because MFA is not enabled">المصادقة متعددة العوامل معطلة حاليًا</string>
182183
</resources>

auth/src/main/res/values-b+es+419/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,5 @@
197197

198198
<!-- Tooltips -->
199199
<string name="fui_new_accounts_disabled_tooltip" translation_description="Tooltip shown when sign-up button is disabled because new accounts are not allowed">This button is currently disabled because new accounts are not allowed</string>
200+
<string name="fui_mfa_disabled_tooltip" translation_description="Tooltip shown when manage MFA button is disabled because MFA is not enabled">Multi-factor authentication is currently disabled</string>
200201
</resources>

auth/src/main/res/values-bg/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,5 @@
179179

180180
<!-- Tooltips -->
181181
<string name="fui_new_accounts_disabled_tooltip" translation_description="Tooltip shown when sign-up button is disabled because new accounts are not allowed">This button is currently disabled because new accounts are not allowed</string>
182+
<string name="fui_mfa_disabled_tooltip" translation_description="Tooltip shown when manage MFA button is disabled because MFA is not enabled">Многофакторната автентификация в момента е деактивирана</string>
182183
</resources>

auth/src/main/res/values-bn/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,5 @@
180180

181181
<!-- Tooltips -->
182182
<string name="fui_new_accounts_disabled_tooltip" translation_description="Tooltip shown when sign-up button is disabled because new accounts are not allowed">This button is currently disabled because new accounts are not allowed</string>
183+
<string name="fui_mfa_disabled_tooltip" translation_description="Tooltip shown when manage MFA button is disabled because MFA is not enabled">মাল্টি-ফ্যাক্টর প্রমাণীকরণ বর্তমানে নিষ্ক্রিয়</string>
183184
</resources>

auth/src/main/res/values-ca/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,4 +180,5 @@
180180

181181
<!-- Tooltips -->
182182
<string name="fui_new_accounts_disabled_tooltip" translation_description="Tooltip shown when sign-up button is disabled because new accounts are not allowed">This button is currently disabled because new accounts are not allowed</string>
183+
<string name="fui_mfa_disabled_tooltip" translation_description="Tooltip shown when manage MFA button is disabled because MFA is not enabled">L\'autenticació multifactor està desactivada actualment</string>
183184
</resources>

auth/src/main/res/values-cs/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,5 @@
179179

180180
<!-- Tooltips -->
181181
<string name="fui_new_accounts_disabled_tooltip" translation_description="Tooltip shown when sign-up button is disabled because new accounts are not allowed">This button is currently disabled because new accounts are not allowed</string>
182+
<string name="fui_mfa_disabled_tooltip" translation_description="Tooltip shown when manage MFA button is disabled because MFA is not enabled">Vícefaktorové ověřování je aktuálně zakázáno</string>
182183
</resources>

0 commit comments

Comments
 (0)