Skip to content

Commit 84ce5fb

Browse files
authored
fix(ui_auth): deprecate screens and widgets that use fetchSignInMethodsForEmail (#153)
Email enumeration protection is on by default for new project. This breaks UniversalEmailSignInScreen and other Firebase UI Auth APIs that use fetchSignInMethodsForEmail under the hood. Read more details here https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection
1 parent 0e93d61 commit 84ce5fb

9 files changed

+53
-13
lines changed

packages/firebase_ui_auth/lib/src/auth_flow.dart

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class AuthCancelledException implements Exception {
2727
/// - [EmailLinkFlow]
2828
/// - [OAuthFlow]
2929
/// - [PhoneAuthFlow]
30-
/// - [UniversalEmailSignInFlow]
3130
///
3231
/// See [AuthFlowBuilder] docs to learn how to wire up the auth flow with the
3332
/// widget tree.

packages/firebase_ui_auth/lib/src/flows/universal_email_sign_in_flow.dart

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import 'package:firebase_auth/firebase_auth.dart';
66
import 'package:firebase_ui_auth/firebase_ui_auth.dart';
77

88
/// A controller interface of the [UniversalEmailSignInFlow].
9+
@Deprecated(
10+
'Email enumeration protection is on by default.'
11+
'Read more here https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection',
12+
)
913
abstract class UniversalEmailSignInController extends AuthController {
1014
/// {@template ui.auth.auth_controller.find_providers_for_email}
1115
/// Finds providers that can be used to sign in with a provided email.
@@ -20,6 +24,10 @@ abstract class UniversalEmailSignInController extends AuthController {
2024
/// An auth flow that resolves providers that are accosicatied with the given
2125
/// email.
2226
/// {@endtemplate}
27+
@Deprecated(
28+
'Email enumeration protection is on by default.'
29+
'Read more here https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection',
30+
)
2331
class UniversalEmailSignInFlow extends AuthFlow<UniversalEmailSignInProvider>
2432
implements UniversalEmailSignInController, UniversalEmailSignInListener {
2533
// {@macro ui.auth.flows.universal_email_sign_in_flow}

packages/firebase_ui_auth/lib/src/providers/auth_provider.dart

+12-10
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,6 @@ void defaultOnAuthError(AuthProvider provider, Object error) {
2121
return;
2222
}
2323

24-
if (error.code == 'account-exists-with-different-credential') {
25-
final email = error.email;
26-
if (email == null) {
27-
throw error;
28-
}
29-
30-
provider.findProvidersForEmail(email, error.credential);
31-
}
32-
3324
throw error;
3425
}
3526

@@ -39,7 +30,6 @@ void defaultOnAuthError(AuthProvider provider, Object error) {
3930
/// - [EmailAuthListener]
4031
/// - [EmailLinkAuthListener]
4132
/// - [PhoneAuthListener]
42-
/// - [UniversalEmailSignInListener]
4333
abstract class AuthListener {
4434
/// Current [AuthProvider] that is being used to authenticate the user.
4535
AuthProvider get provider;
@@ -64,9 +54,17 @@ abstract class AuthListener {
6454
void onCredentialLinked(AuthCredential credential);
6555

6656
/// Called before an attempt to fetch available providers for the email.
57+
@Deprecated(
58+
'Email enumeration protection is on by default.'
59+
'Read more here https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection',
60+
)
6761
void onBeforeProvidersForEmailFetch();
6862

6963
/// Called when available providers for the email were successfully fetched.
64+
@Deprecated(
65+
'Email enumeration protection is on by default.'
66+
'Read more here https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection',
67+
)
7068
void onDifferentProvidersFound(
7169
String email,
7270
List<String> providers,
@@ -139,6 +137,10 @@ abstract class AuthProvider<T extends AuthListener, K extends AuthCredential> {
139137
}
140138

141139
/// Fetches available providers for the given [email].
140+
@Deprecated(
141+
'Email enumeration protection is on by default.'
142+
'Read more here https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection',
143+
)
142144
void findProvidersForEmail(
143145
String email, [
144146
AuthCredential? credential,

packages/firebase_ui_auth/lib/src/providers/universal_email_sign_in_provider.dart

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import 'package:flutter/foundation.dart';
77
import 'package:firebase_ui_auth/firebase_ui_auth.dart';
88

99
/// A [UniversalEmailSignInFlow] lifecycle listener.
10+
@Deprecated(
11+
'Email enumeration protection is on by default.'
12+
'Read more here https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection',
13+
)
1014
abstract class UniversalEmailSignInListener extends AuthListener {
1115
@override
1216
void onBeforeProvidersForEmailFetch();
@@ -21,6 +25,10 @@ abstract class UniversalEmailSignInListener extends AuthListener {
2125

2226
/// A provider that resolves available authentication methods for a given
2327
/// email.
28+
@Deprecated(
29+
'Email enumeration protection is on by default.'
30+
'Read more here https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection',
31+
)
2432
class UniversalEmailSignInProvider
2533
extends AuthProvider<UniversalEmailSignInListener, AuthCredential> {
2634
@override

packages/firebase_ui_auth/lib/src/screens/universal_email_sign_in_screen.dart

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import '../widgets/internal/universal_page_route.dart';
99
import 'internal/multi_provider_screen.dart';
1010

1111
/// A screen that allows to resolve previously used providers for a given email.
12+
@Deprecated(
13+
'Email enumeration protection is on by default.'
14+
'Read more here https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection',
15+
)
1216
class UniversalEmailSignInScreen extends MultiProviderScreen {
1317
/// A callback that is being called when providers fetch request completed.
1418
final ProvidersFoundCallback? onProvidersFound;

packages/firebase_ui_auth/lib/src/views/find_providers_for_email_view.dart

+12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import 'package:firebase_ui_localizations/firebase_ui_localizations.dart';
1111
import '../widgets/internal/title.dart';
1212

1313
/// A callback that is being called when providers fetch request is completed.
14+
@Deprecated(
15+
'Email enumeration protection is on by default.'
16+
'Read more here https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection',
17+
)
1418
typedef ProvidersFoundCallback = void Function(
1519
String email,
1620
List<String> providers,
@@ -19,6 +23,10 @@ typedef ProvidersFoundCallback = void Function(
1923
/// {@template ui.auth.views.find_providers_for_email_view}
2024
/// A view that could be used to build a custom [UniversalEmailSignInScreen].
2125
/// {@endtemplate}
26+
@Deprecated(
27+
'Email enumeration protection is on by default.'
28+
'Read more here https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection',
29+
)
2230
class FindProvidersForEmailView extends StatefulWidget {
2331
final ProvidersFoundCallback? onProvidersFound;
2432

@@ -37,6 +45,10 @@ class FindProvidersForEmailView extends StatefulWidget {
3745
_FindProvidersForEmailViewState();
3846
}
3947

48+
@Deprecated(
49+
'Email enumeration protection is on by default.'
50+
'Read more here https://cloud.google.com/identity-platform/docs/admin/email-enumeration-protection',
51+
)
4052
class _FindProvidersForEmailViewState extends State<FindProvidersForEmailView> {
4153
final formKey = GlobalKey<FormState>();
4254
final emailCtrl = TextEditingController();

packages/firebase_ui_auth/lib/src/widgets/auth_flow_builder.dart

+5-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ typedef StateTransitionListener<T extends AuthController> = void Function(
5656
/// * [EmailLinkFlow]
5757
/// * [OAuthFlow]
5858
/// * [PhoneAuthFlow]
59-
/// * [UniversalEmailSignInFlow].
6059
///
6160
/// An example of how to build a custom email sign up form using
6261
/// [AuthFlowBuilder]:
@@ -138,7 +137,6 @@ class AuthFlowBuilder<T extends AuthController> extends StatefulWidget {
138137
/// The following providers are optional to provide:
139138
/// * [EmailAuthController]
140139
/// * [PhoneAuthController]
141-
/// * [UniversalEmailSignInController]
142140
final AuthProvider? provider;
143141

144142
/// An optional instance of the [AuthFlow].
@@ -228,7 +226,10 @@ class _AuthFlowBuilderState<T extends AuthController>
228226
return EmailAuthProvider();
229227
case PhoneAuthController:
230228
return PhoneAuthProvider();
229+
230+
// ignore: deprecated_member_use_from_same_package
231231
case UniversalEmailSignInController:
232+
// ignore: deprecated_member_use_from_same_package
232233
return UniversalEmailSignInProvider();
233234
default:
234235
throw Exception("Can't create $T provider");
@@ -268,7 +269,9 @@ class _AuthFlowBuilderState<T extends AuthController>
268269
action: widget.action,
269270
auth: widget.auth,
270271
);
272+
// ignore: deprecated_member_use_from_same_package
271273
} else if (provider is UniversalEmailSignInProvider) {
274+
// ignore: deprecated_member_use_from_same_package
272275
return UniversalEmailSignInFlow(
273276
provider: provider,
274277
action: widget.action,

packages/firebase_ui_auth/test/flows/universal_email_sign_in_flow_test.dart

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
// ignore_for_file: deprecated_member_use_from_same_package
6+
57
import 'package:firebase_auth/firebase_auth.dart';
68
import 'package:flutter_test/flutter_test.dart';
79
import 'package:firebase_ui_auth/firebase_ui_auth.dart';

tests/integration_test/firebase_ui_auth/universal_email_sign_in_screen_test.dart

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
// ignore_for_file: deprecated_member_use
6+
57
import 'package:firebase_auth/firebase_auth.dart'
68
hide EmailAuthProvider, PhoneAuthProvider;
79
import 'package:firebase_core/firebase_core.dart';

0 commit comments

Comments
 (0)