firebase / flutterfire

πŸ”₯ A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.71k stars 3.97k forks source link

πŸ› [firebase_ui_auth] Apple Sign-In is not passing DisplayName #10679

Closed valentinozegna closed 1 year ago

valentinozegna commented 1 year ago

Bug report

I am developing a Flutter app using firebase_ui_auth, firebase_ui_oauth_google and firebase_ui_oauth_apple. When I try to Sign In With Apple, the displayName is not passed to the SignInScreen via FirebaseAuth.instance.authStateChanges(). I only get the email, every other field is null.

Steps to reproduce

  1. Setup the desired FirebaseAusign-in providers in your main.dart.

  2. Create a firebase_ui_Auth SignInScreen and listen for authentication state changes via FirebaseAuth.instance.authStateChanges().

  3. When the user signs-in with Apple, snapshot.data contains the user's email, but doesn't contain the displayName.

Expected behavior

displayName should contain the full name of the user, not NULL.

Sample project

// main.dart

// Framework
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart' show CupertinoScrollBehavior;
import 'package:flutter/services.dart';
import 'dart:io' show Platform;

// Providers
import 'package:provider/provider.dart';
import '../providers/events_provider.dart';
import '../providers/search_provider.dart';
import '../providers/user_provider.dart';
import '../providers/notification_provider.dart';

// Firebase
import 'package:firebase_auth/firebase_auth.dart' hide EmailAuthProvider;
import 'package:firebase_ui_auth/firebase_ui_auth.dart';
import 'package:firebase_ui_oauth_apple/firebase_ui_oauth_apple.dart';
import 'package:firebase_ui_oauth_google/firebase_ui_oauth_google.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';

// Screens
import '../main_screen.dart';
import '../authentication/authentication.dart';

// Utilities
import '../utils/styles.dart';
import '../utils/constants.dart';
import '../firebase_options.dart';

@pragma('vm:entry-point')
Future<void> _messageHandler(RemoteMessage message) async {
  // Listen for incoming notifications when the app is in the background
  if (kDebugMode) {
    print("DEBUG: Main - Received background message with messageID: ${message.messageId}");
    print('---> Body is: ${message.notification?.body}');
  }
}

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  late String googleClientId;
  if (Platform.isAndroid) {
    if (kDebugMode) {
      googleClientId = <client_id_here>;
    } else {
      googleClientId = "<client_id_here>";
    }
  } else if (Platform.isIOS) {
    googleClientId = "<client_id_here>";
  }

  FirebaseUIAuth.configureProviders([
    GoogleProvider(clientId: googleClientId),
    AppleProvider(),
  ]);

  runApp(
    MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => EventsProvider()),
        ChangeNotifierProvider(create: (_) => SearchProvider()),
        ChangeNotifierProvider(create: (_) => UserProvider()),
        ChangeNotifierProvider(create: (_) => NotificationProvider()),
      ],
      child: const MyApp(),
    ),
  );
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    Provider.of<NotificationProvider>(context, listen: false).init();
  }

  @override
  Widget build(BuildContext context) {
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp,
    ]);

    return MaterialApp(
      debugShowCheckedModeBanner: false,
      scrollBehavior: const CupertinoScrollBehavior(),
      theme: Styles.airPlazaThemeData(ThemeMode.light, context),
      darkTheme: Styles.airPlazaThemeData(ThemeMode.dark, context),
      themeMode: ThemeMode.dark, // Forced to dark at all times
      initialRoute: FirebaseAuth.instance.currentUser == null ? routeAuth : routeMain,
      routes: {
        routeAuth: (context) {
          final MediaQueryData data = MediaQuery.of(context);
          return MediaQuery(
            data: data.copyWith(textScaleFactor: data.textScaleFactor > 1.35 ? 1.35 : data.textScaleFactor),
            child: const AuthenticationScreen(),
          );
        },
        routeMain: (context) {
          final MediaQueryData data = MediaQuery.of(context);
          return MediaQuery(
            data: data.copyWith(textScaleFactor: data.textScaleFactor > 1.35 ? 1.35 : data.textScaleFactor),
            child: const MainScreen(),
          );
        }
      },
    );
  }
}

class AuthenticationScreen extends StatelessWidget {
  const AuthenticationScreen({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return StreamBuilder<User?>(
      stream: FirebaseAuth.instance.authStateChanges(),
      builder: (context, snapshot) {
        if (kDebugMode) print("DEBUG: Authentication StreamBuilder snapshot.data: ${snapshot.data}");
        return SignInScreen(
          auth: FirebaseAuth.instance,
          showAuthActionSwitch: false,
          actions: [
            AuthStateChangeAction<SignedIn>((context, _) {
              Navigator.pushReplacement(
                context,
                MaterialPageRoute(builder: (context) => const MainScreen()),
              );
            }),
            AuthStateChangeAction<UserCreated>((context, _) {
              Navigator.pushReplacement(
                context,
                MaterialPageRoute(builder: (context) => const MainScreen()),
              );
            }),
          ],
          headerBuilder: (context, constraints, _) {
            return Image.asset(
              'lib/assets/1024.png',
              fit: BoxFit.fitHeight,
            );
          },
          subtitleBuilder: (context, action) {
            return Padding(
              padding: const EdgeInsets.only(bottom: 8),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  const Text("Welcome!", style: Styles.hugeTextStyleBoldBlue),
                  Text(
                    action == AuthAction.signIn
                        ? 'Choose your favorite sign-in method.'
                        : 'Please create an account to continue',
                    style: Styles.bigTextStyle,
                  ),
                ],
              ),
            );
          },
        );
      },
    );
  }
}

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` flutter doctor -v [βœ“] Flutter (Channel stable, 3.7.8, on macOS 13.2.1 22D68 darwin-arm64, locale en-US) β€’ Flutter version 3.7.8 on channel stable at /Users/valentino/Flutter/flutter β€’ Upstream repository https://github.com/flutter/flutter.git β€’ Framework revision 90c64ed42b (7 days ago), 2023-03-21 11:27:08 -0500 β€’ Engine revision 9aa7816315 β€’ Dart version 2.19.5 β€’ DevTools version 2.20.1 [βœ“] Android toolchain - develop for Android devices (Android SDK version 33.0.0) β€’ Android SDK at /Users/valentino/Library/Android/sdk β€’ Platform android-33, build-tools 33.0.0 β€’ Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java β€’ Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301) β€’ All Android licenses accepted. [βœ“] Xcode - develop for iOS and macOS (Xcode 14.2) β€’ Xcode at /Applications/Xcode.app/Contents/Developer β€’ Build 14C18 β€’ CocoaPods version 1.12.0 [βœ“] Chrome - develop for the web β€’ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [βœ“] Android Studio (version 2022.1) β€’ Android Studio at /Applications/Android Studio.app/Contents β€’ Flutter plugin can be installed from: πŸ”¨ https://plugins.jetbrains.com/plugin/9212-flutter β€’ Dart plugin can be installed from: πŸ”¨ https://plugins.jetbrains.com/plugin/6351-dart β€’ Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301) [βœ“] Connected device (3 available) β€’ iPhone XS Max (mobile) β€’ 00008020-000130A82600013A β€’ ios β€’ iOS 16.3.1 20D67 β€’ macOS (desktop) β€’ macos β€’ darwin-arm64 β€’ macOS 13.2.1 22D68 darwin-arm64 β€’ Chrome (web) β€’ chrome β€’ web-javascript β€’ Google Chrome 111.0.5563.146 [βœ“] HTTP Host Availability β€’ All required HTTP hosts are available β€’ No issues found! ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` flutter pub deps -- --style=compact Dart SDK 2.19.5 Flutter SDK 3.7.8 airplaza 1.1.4+21 dependencies: - add_2_calendar 2.2.3 [flutter] - animations 2.0.7 [flutter] - cached_network_image 3.2.3 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web] - cloud_firestore 4.4.5 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta] - cupertino_icons 1.0.5 - date_format 2.0.7 - firebase_analytics 10.1.6 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_auth 4.3.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_core 2.8.0 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_messaging 14.3.0 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - firebase_remote_config 3.0.15 [firebase_core firebase_core_platform_interface firebase_remote_config_platform_interface firebase_remote_config_web flutter] - firebase_ui_auth 1.1.17 [email_validator firebase_auth firebase_core firebase_dynamic_links firebase_ui_localizations firebase_ui_oauth flutter flutter_localizations flutter_svg] - firebase_ui_oauth_apple 1.0.24 [firebase_auth firebase_ui_oauth flutter] - firebase_ui_oauth_google 1.0.24 [firebase_auth firebase_ui_oauth flutter google_sign_in] - flutter 0.0.0 [characters collection js material_color_utilities meta vector_math sky_engine] - get 4.6.5 [flutter] - google_api_headers 1.5.0+1 [flutter package_info_plus] - google_maps_webservice 0.0.20-nullsafety.5 [http meta json_annotation] - http 0.13.5 [async http_parser meta path] - intl 0.17.0 [clock path] - maps_launcher 2.2.0 [flutter flutter_web_plugins url_launcher] - package_info_plus 3.0.3 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface win32] - provider 6.0.5 [collection flutter nested] - rxdart 0.27.7 dev dependencies: - flutter_lints 2.0.1 [lints] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters collection js matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph] transitive dependencies: - _flutterfire_internals 1.0.18 [collection firebase_core firebase_core_platform_interface flutter meta] - async 2.10.0 [collection meta] - boolean_selector 2.1.1 [source_span string_scanner] - cached_network_image_platform_interface 2.0.0 [flutter flutter_cache_manager] - cached_network_image_web 1.0.2 [flutter flutter_cache_manager cached_network_image_platform_interface] - characters 1.2.1 - clock 1.1.1 - cloud_firestore_platform_interface 5.11.5 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - cloud_firestore_web 3.3.5 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js] - collection 1.17.0 - crypto 3.0.2 [typed_data] - desktop_webview_auth 0.0.11 [crypto flutter http flutter_web_plugins plugin_platform_interface] - email_validator 2.1.17 - fake_async 1.3.1 [clock collection] - ffi 2.0.1 - file 6.1.4 [meta path] - firebase_analytics_platform_interface 3.3.23 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.5.1+14 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_auth_platform_interface 6.12.0 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 5.2.10 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta] - firebase_core_platform_interface 4.5.3 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.2.2 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_dynamic_links 5.0.17 [firebase_core firebase_core_platform_interface firebase_dynamic_links_platform_interface flutter meta plugin_platform_interface] - firebase_dynamic_links_platform_interface 0.2.3+32 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_platform_interface 4.2.16 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.2.17 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - firebase_remote_config_platform_interface 1.1.35 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_remote_config_web 1.1.24 [firebase_core firebase_core_web firebase_remote_config_platform_interface flutter flutter_web_plugins js] - firebase_ui_localizations 1.2.0 [flutter flutter_localizations intl path] - firebase_ui_oauth 1.1.17 [desktop_webview_auth firebase_auth firebase_ui_auth flutter_svg flutter] - flutter_blurhash 0.7.0 [flutter] - flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid] - flutter_localizations 0.0.0 [flutter intl characters clock collection js material_color_utilities meta path vector_math] - flutter_svg 1.1.6 [flutter meta path_drawing vector_math xml] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math] - google_identity_services_web 0.2.0 [js meta] - google_sign_in 6.0.2 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web] - google_sign_in_android 6.1.8 [flutter google_sign_in_platform_interface] - google_sign_in_ios 5.6.1 [flutter google_sign_in_platform_interface] - google_sign_in_platform_interface 2.3.1 [flutter plugin_platform_interface quiver] - google_sign_in_web 0.11.0+2 [flutter flutter_web_plugins google_identity_services_web google_sign_in_platform_interface http js] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - js 0.6.5 [meta] - json_annotation 4.8.0 [meta] - lints 2.0.1 - matcher 0.12.13 [meta stack_trace] - material_color_utilities 0.2.0 - meta 1.8.0 - nested 1.0.0 [flutter] - octo_image 1.0.2 [flutter flutter_blurhash] - package_info_plus_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - path 1.8.2 - path_drawing 1.0.1 [vector_math meta path_parsing flutter] - path_parsing 1.0.1 [vector_math meta] - path_provider 2.0.14 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows] - path_provider_android 2.0.24 [flutter path_provider_platform_interface] - path_provider_foundation 2.2.0 [flutter path_provider_platform_interface] - path_provider_linux 2.1.10 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_platform_interface 2.0.6 [flutter platform plugin_platform_interface] - path_provider_windows 2.1.5 [ffi flutter path path_provider_platform_interface win32] - pedantic 1.11.1 - petitparser 5.1.0 [meta] - platform 3.1.0 - plugin_platform_interface 2.1.4 [meta] - process 4.2.4 [file path platform] - quiver 3.2.1 [matcher] - sky_engine 0.0.99 - source_span 1.9.1 [collection path term_glyph] - sqflite 2.2.6 [flutter sqflite_common path] - sqflite_common 2.4.3 [synchronized path meta] - stack_trace 1.11.0 [path] - stream_channel 2.1.1 [async] - string_scanner 1.2.0 [source_span] - synchronized 3.0.1 - term_glyph 1.2.1 - test_api 0.4.16 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - typed_data 1.3.1 [collection] - url_launcher 6.1.10 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - url_launcher_android 6.0.26 [flutter url_launcher_platform_interface] - url_launcher_ios 6.1.3 [flutter url_launcher_platform_interface] - url_launcher_linux 3.0.4 [flutter url_launcher_platform_interface] - url_launcher_macos 3.0.4 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.1.2 [flutter plugin_platform_interface] - url_launcher_web 2.0.16 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.5 [flutter url_launcher_platform_interface] - uuid 3.0.7 [crypto] - vector_math 2.1.4 - win32 3.1.3 [ffi] - xdg_directories 1.0.0 [meta path process] - xml 6.2.2 [collection meta petitparser] ```

darshankawar commented 1 year ago

Thanks for the report @Valent1 A similar issue has been recently fixed at native iOS SDK side https://firebase.google.com/support/release-notes/ios#10.7.0 that you can check and see if it helps in your case or not.

Related flutterfire issue: https://github.com/firebase/flutterfire/issues/9662

Lyokone commented 1 year ago

@Valent1 It is fixed in firebase_auth 4.4.0.