Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [firebase_auth] UserCredential does not contain displayName when signing in and email when linking with Apple on iOS #9662

Closed
felixgabler opened this issue Oct 3, 2022 · 35 comments · Fixed by #10652
Assignees
Labels
blocked: firebase-sdk platform: ios Issues / PRs which are specifically for iOS. plugin: auth resolution: fixed A fix has been merged or is pending merge from a PR. type: bug Something isn't working

Comments

@felixgabler
Copy link

Bug report

Describe the bug
The signInWithProvider returns a UserCredential where displayName is missing in the apple.com providerData.

Additionally, the linkWithProvider returns a UserCredential where both displayName and email are missing in the apple.com providerData.

This happens for new Apple IDs too (for testing with existing IDs, make sure to disconnect them from the App through the Apple ID settings).

On Android, it works correctly!

Steps to reproduce

Steps to reproduce the behavior:

  1. Go to the Apple ID setting to make sure the Apple ID is disconnected from the app and will appear as a new, fresh connection.
  2. Run the sample code and sign in on the Apple system dialog.
  3. The resulting user credentials will not have a name.

Expected behavior

The UserCredential should return the displayName (and email) as it does on Android.

Sample project

Here is the relevant code:

Future<String> signInWithApple() async {
    final appleProvider = AppleAuthProvider()
      ..addScope('email')
      ..addScope('name');
    final UserCredential userCredential;
    if (kIsWeb) {
      userCredential = await FirebaseAuth.instance.signInWithPopup(appleProvider);
    } else {
      userCredential = await FirebaseAuth.instance.signInWithProvider(appleProvider);
    }
    // Will return null
    return userCredential.user?.providerData.firstWhereOrNull((userInfo) => userInfo.providerId == 'apple.com')?.displayName;
}

Future<String> linkApple() async {
    final appleProvider = AppleAuthProvider()..addScope('email');
    final UserCredential userCredential;
    if (kIsWeb) {
      userCredential = await FirebaseAuth.instance.currentUser!.linkWithPopup(appleProvider);
    } else {
      userCredential = await FirebaseAuth.instance.currentUser!.linkWithProvider(appleProvider);
    }
    // Will return null
    return userCredential.user?.providerData.firstWhereOrNull((userInfo) => userInfo.providerId == 'apple.com')?.email;
}

Additional context

I know that Apple only returns it on the first sign in. This is however NOT the issue here because it works on Android if the Apple ID is successfully disconnected. Tested on both real devices and simulator. Also tested with a totally new Apple ID.


Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.3.3, on macOS 12.6 21G115 darwin-arm, locale en-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2022.2.2)
[✓] Connected device (3 available)
[✓] HTTP Host Availability

• No issues found!

Flutter dependencies

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

Click To Expand
Dart SDK 2.18.2
Flutter SDK 3.3.3
weo_app 1.2.0-alpha.1

dependencies:
- another_xlider 1.1.2 [flutter]
- app_settings 4.1.8 [flutter]
- async 2.9.0 [collection meta]
- background_fetch 1.1.1 [flutter]
- badges 2.0.3 [flutter]
- better_player 0.0.81 [flutter cupertino_icons wakelock meta flutter_widget_from_html_core visibility_detector path_provider collection xml]
- cached_network_image 3.2.2 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web]
- characters 1.2.1
- clock 1.1.1
- cloud_firestore 3.5.0 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- cloud_functions 3.3.9 [cloud_functions_platform_interface cloud_functions_web firebase_core firebase_core_platform_interface flutter]
- collection 1.16.0
- connectivity_plus 2.3.7 [flutter connectivity_plus_platform_interface connectivity_plus_linux connectivity_plus_macos connectivity_plus_web connectivity_plus_windows]
- crypto 3.0.2 [typed_data]
- decimal 2.3.0 [rational]
- equatable 2.0.5 [collection meta]
- expandable_bottom_bar 2.0.2 [flutter]
- file_picker 5.2.0+1 [flutter flutter_web_plugins flutter_plugin_android_lifecycle plugin_platform_interface ffi path win32]
- firebase_analytics 9.3.7 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter]
- firebase_auth 3.11.1 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 1.24.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_crashlytics 2.8.12 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace]
- firebase_dynamic_links 4.3.9 [firebase_core firebase_core_platform_interface firebase_dynamic_links_platform_interface flutter meta plugin_platform_interface]
- firebase_messaging 13.0.4 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- firebase_performance 0.8.3+2 [firebase_core firebase_core_platform_interface firebase_performance_platform_interface firebase_performance_web flutter]
- firebase_storage 10.3.10 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter]
- fl_chart 0.55.2 [flutter equatable]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid]
- flutter_chat_types 3.4.5 [equatable json_annotation meta]
- flutter_chat_ui 1.6.4 [diffutil_dart equatable flutter flutter_chat_types flutter_link_previewer flutter_parsed_text intl meta photo_view url_launcher visibility_detector]
- flutter_contacts 1.1.5 [flutter]
- flutter_health_fit 0.1.0 [flutter]
- flutter_linkify 5.0.2 [flutter linkify]
- flutter_local_notifications 11.0.1 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone]
- flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math]
- flutter_native_timezone 2.0.0 [flutter_web_plugins flutter js]
- flutter_page_transition 0.1.6 [flutter]
- flutter_reaction_button 2.0.1+2 [flutter]
- flutter_speed_dial 6.0.0 [flutter]
- flutter_svg 1.1.5 [flutter meta path_drawing vector_math xml]
- freezed_annotation 2.1.0 [collection json_annotation meta]
- geolocator 9.0.2 [flutter geolocator_platform_interface geolocator_android geolocator_apple geolocator_web geolocator_windows]
- get 4.6.5 [flutter]
- google_fonts 3.0.1 [flutter http path_provider crypto]
- google_geocoding 0.2.0 [flutter http]
- google_place 0.4.7 [http]
- google_sign_in 5.4.2 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web]
- image_cropper 3.0.0 [flutter image_cropper_platform_interface image_cropper_for_web]
- image_picker 0.8.5+3 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_platform_interface]
- in_app_review 2.0.4 [flutter in_app_review_platform_interface]
- intl 0.17.0 [clock path]
- json_annotation 4.6.0 [meta]
- lottie 1.4.3 [archive flutter path vector_math]
- meilisearch 0.6.0 [dio crypto]
- open_filex 4.1.1 [flutter ffi]
- package_info_plus 1.4.3+1 [flutter package_info_plus_platform_interface package_info_plus_linux package_info_plus_macos package_info_plus_windows package_info_plus_web]
- permission_handler 10.0.2 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface]
- phone_number 1.0.0 [flutter meta]
- pref 2.6.0 [flutter logging shared_preferences]
- rxdart 0.27.5
- scroll_to_index 3.0.1 [flutter]
- share_plus 4.4.0 [meta mime flutter share_plus_platform_interface share_plus_linux share_plus_macos share_plus_windows share_plus_web]
- timezone 0.9.0 [path]
- url_launcher 6.1.6 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- uuid 3.0.6 [crypto]
- wakelock 0.6.2 [flutter meta wakelock_macos wakelock_platform_interface wakelock_web wakelock_windows]
- youtube_explode_dart 1.12.1 [collection freezed_annotation html http http_parser json_annotation meta xml]

dev dependencies:
- build_runner 2.2.1 [args async analyzer build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style frontend_server_client glob graphs http_multi_server io js logging meta mime package_config path pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web_socket_channel yaml]
- dart_code_metrics 4.19.1 [analyzer analyzer_plugin ansicolor args collection crypto file glob html meta path source_span xml yaml]
- 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 matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph]
- freezed 2.1.0+1 [analyzer build build_config collection meta source_gen freezed_annotation json_annotation]
- intl_utils 2.7.0 [analyzer archive args dart_style http intl path petitparser yaml]
- json_serializable 6.3.1 [analyzer async build build_config collection json_annotation meta path pub_semver pubspec_parse source_gen source_helper]

dependency overrides:
- json_annotation 4.6.0 [meta]

transitive dependencies:
- _fe_analyzer_shared 47.0.0 [meta]
- _flutterfire_internals 1.0.1 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- analyzer 4.7.0 [_fe_analyzer_shared collection convert crypto glob meta package_config path pub_semver source_span watcher yaml]
- analyzer_plugin 0.10.0 [analyzer collection dart_style pub_semver yaml]
- ansicolor 2.0.1
- archive 3.3.1 [crypto path]
- args 2.3.1
- boolean_selector 2.1.0 [source_span string_scanner]
- build 2.3.1 [analyzer async convert crypto glob logging meta path]
- build_config 1.1.0 [checked_yaml json_annotation path pubspec_parse yaml]
- build_daemon 3.1.0 [built_collection built_value http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel]
- build_resolvers 2.0.10 [analyzer async build crypto graphs logging path package_config pool pub_semver stream_transform yaml]
- build_runner_core 7.2.4 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta path package_config pool timing watcher yaml]
- built_collection 5.1.1
- built_value 8.4.1 [built_collection collection fixnum meta]
- 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]
- checked_yaml 2.0.1 [json_annotation source_span yaml]
- cloud_firestore_platform_interface 5.7.6 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 2.8.9 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js]
- cloud_functions_platform_interface 5.1.18 [firebase_core flutter meta plugin_platform_interface]
- cloud_functions_web 4.3.7 [cloud_functions_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- code_builder 4.3.0 [built_collection built_value collection matcher meta]
- connectivity_plus_linux 1.3.1 [flutter connectivity_plus_platform_interface meta nm]
- connectivity_plus_macos 1.2.4 [connectivity_plus_platform_interface flutter]
- connectivity_plus_platform_interface 1.2.1 [flutter meta plugin_platform_interface]
- connectivity_plus_web 1.2.4 [connectivity_plus_platform_interface flutter_web_plugins flutter js]
- connectivity_plus_windows 1.2.2 [connectivity_plus_platform_interface flutter]
- convert 3.0.2 [typed_data]
- cross_file 0.3.3+2 [js meta]
- csslib 0.17.2 [source_span]
- cupertino_icons 1.0.5
- dart_style 2.2.4 [analyzer args path pub_semver source_span]
- dbus 0.7.8 [args ffi meta xml]
- diffutil_dart 3.0.0
- dio 4.0.6 [http_parser path]
- fake_async 1.3.1 [clock collection]
- ffi 2.0.1
- file 6.1.4 [meta path]
- firebase 9.0.3 [http http_parser js]
- firebase_analytics_platform_interface 3.3.6 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_analytics_web 0.4.2+6 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- firebase_auth_platform_interface 6.10.0 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 4.6.0 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta]
- firebase_core_platform_interface 4.5.1 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 1.7.3 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_crashlytics_platform_interface 3.2.18 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_dynamic_links_platform_interface 0.2.3+14 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_platform_interface 4.1.6 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_messaging_web 3.1.6 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta]
- firebase_performance_platform_interface 0.1.1+18 [_flutterfire_internals firebase_core flutter plugin_platform_interface]
- firebase_performance_web 0.1.1+7 [_flutterfire_internals firebase firebase_core firebase_core_web firebase_performance_platform_interface flutter flutter_web_plugins js]
- firebase_storage_platform_interface 4.1.18 [collection firebase_core flutter meta plugin_platform_interface]
- firebase_storage_web 3.3.8 [_flutterfire_internals async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta]
- fixnum 1.0.1
- flutter_blurhash 0.7.0 [flutter]
- flutter_link_previewer 3.0.1 [flutter flutter_chat_types flutter_linkify html http linkify meta url_launcher]
- flutter_local_notifications_linux 1.0.0 [flutter flutter_local_notifications_platform_interface dbus path xdg_directories]
- flutter_local_notifications_platform_interface 6.0.0 [flutter plugin_platform_interface]
- flutter_parsed_text 2.2.1 [flutter]
- flutter_plugin_android_lifecycle 2.0.7 [flutter]
- flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math]
- flutter_widget_from_html_core 0.8.5+3 [csslib flutter fwfh_text_style html]
- frontend_server_client 2.1.3 [async path]
- fwfh_text_style 2.22.08+1 [flutter]
- geolocator_android 4.1.3 [flutter geolocator_platform_interface]
- geolocator_apple 2.2.2 [flutter geolocator_platform_interface]
- geolocator_platform_interface 4.0.6 [flutter plugin_platform_interface vector_math meta]
- geolocator_web 2.1.6 [flutter flutter_web_plugins geolocator_platform_interface]
- geolocator_windows 0.1.1 [flutter geolocator_platform_interface]
- glob 2.1.0 [async collection file path string_scanner]
- google_sign_in_android 6.1.1 [flutter google_sign_in_platform_interface]
- google_sign_in_ios 5.5.0 [flutter google_sign_in_platform_interface]
- google_sign_in_platform_interface 2.3.0 [flutter plugin_platform_interface quiver]
- google_sign_in_web 0.10.2 [flutter flutter_web_plugins google_sign_in_platform_interface js]
- graphs 2.1.0 [collection]
- html 0.15.0 [csslib source_span]
- http 0.13.5 [async http_parser meta path]
- http_multi_server 3.2.1 [async]
- http_parser 4.0.1 [collection source_span string_scanner typed_data]
- image_cropper_for_web 1.0.2 [flutter flutter_web_plugins image_cropper_platform_interface js]
- image_cropper_platform_interface 3.0.2 [flutter plugin_platform_interface http]
- image_picker_android 0.8.5+3 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface]
- image_picker_for_web 2.1.10 [flutter flutter_web_plugins image_picker_platform_interface]
- image_picker_ios 0.8.6+1 [flutter image_picker_platform_interface]
- image_picker_platform_interface 2.6.2 [cross_file flutter http plugin_platform_interface]
- in_app_review_platform_interface 2.0.4 [flutter url_launcher plugin_platform_interface platform]
- io 1.0.3 [meta path string_scanner]
- js 0.6.4
- linkify 4.1.0
- lints 2.0.0
- logging 1.0.2
- matcher 0.12.12 [stack_trace]
- material_color_utilities 0.1.5
- meta 1.8.0
- mime 1.0.2
- nm 0.5.0 [dbus]
- octo_image 1.0.2 [flutter flutter_blurhash]
- package_config 2.1.0 [path]
- package_info_plus_linux 1.0.5 [package_info_plus_platform_interface flutter path]
- package_info_plus_macos 1.3.0 [flutter]
- package_info_plus_platform_interface 1.0.2 [flutter meta plugin_platform_interface]
- package_info_plus_web 1.0.5 [flutter flutter_web_plugins http meta package_info_plus_platform_interface]
- package_info_plus_windows 2.1.0 [package_info_plus_platform_interface ffi flutter win32]
- 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.11 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
- path_provider_android 2.0.20 [flutter path_provider_platform_interface]
- path_provider_ios 2.0.11 [flutter path_provider_platform_interface]
- path_provider_linux 2.1.7 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_macos 2.0.6 [flutter path_provider_platform_interface]
- path_provider_platform_interface 2.0.5 [flutter platform plugin_platform_interface]
- path_provider_windows 2.1.3 [ffi flutter path path_provider_platform_interface win32]
- pedantic 1.11.1
- permission_handler_android 10.0.0 [flutter permission_handler_platform_interface]
- permission_handler_apple 9.0.4 [flutter permission_handler_platform_interface]
- permission_handler_platform_interface 3.8.0 [flutter meta plugin_platform_interface]
- permission_handler_windows 0.1.0 [flutter permission_handler_platform_interface]
- petitparser 5.0.0 [meta]
- photo_view 0.14.0 [flutter]
- platform 3.1.0
- plugin_platform_interface 2.1.3 [meta]
- pool 1.5.1 [async stack_trace]
- process 4.2.4 [file path platform]
- pub_semver 2.1.1 [collection meta]
- pubspec_parse 1.2.1 [checked_yaml collection json_annotation pub_semver yaml]
- quiver 3.1.0 [matcher]
- rational 2.2.0
- share_plus_linux 3.0.0 [share_plus_platform_interface file flutter meta url_launcher]
- share_plus_macos 3.0.1 [share_plus_platform_interface flutter]
- share_plus_platform_interface 3.0.3 [flutter meta mime plugin_platform_interface]
- share_plus_web 3.0.1 [share_plus_platform_interface url_launcher flutter flutter_web_plugins meta]
- share_plus_windows 3.0.1 [share_plus_platform_interface flutter meta url_launcher]
- shared_preferences 2.0.15 [flutter shared_preferences_android shared_preferences_ios shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- shared_preferences_android 2.0.13 [flutter shared_preferences_platform_interface]
- shared_preferences_ios 2.1.1 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.1.1 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]
- shared_preferences_macos 2.0.4 [flutter shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.1.0 [flutter plugin_platform_interface]
- shared_preferences_web 2.0.4 [flutter flutter_web_plugins shared_preferences_platform_interface]
- shared_preferences_windows 2.1.1 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- shelf 1.4.0 [async collection http_parser path stack_trace stream_channel]
- shelf_web_socket 1.0.2 [shelf stream_channel web_socket_channel]
- sky_engine 0.0.99
- source_gen 1.2.5 [analyzer async build dart_style glob meta path source_span yaml]
- source_helper 1.3.3 [analyzer collection source_gen]
- source_span 1.9.0 [collection path term_glyph]
- sqflite 2.1.0 [flutter sqflite_common path]
- sqflite_common 2.3.0 [synchronized path meta]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- stream_transform 2.0.0
- string_scanner 1.1.1 [source_span]
- synchronized 3.0.0+3
- term_glyph 1.2.1
- test_api 0.4.12 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
- timing 1.0.0 [json_annotation]
- typed_data 1.3.1 [collection]
- url_launcher_android 6.0.19 [flutter url_launcher_platform_interface]
- url_launcher_ios 6.0.17 [flutter url_launcher_platform_interface]
- url_launcher_linux 3.0.1 [flutter url_launcher_platform_interface]
- url_launcher_macos 3.0.1 [flutter url_launcher_platform_interface]
- url_launcher_platform_interface 2.1.1 [flutter plugin_platform_interface]
- url_launcher_web 2.0.13 [flutter flutter_web_plugins url_launcher_platform_interface]
- url_launcher_windows 3.0.1 [flutter url_launcher_platform_interface]
- vector_math 2.1.2
- visibility_detector 0.3.3 [flutter]
- wakelock_macos 0.4.0 [flutter flutter_web_plugins wakelock_platform_interface]
- wakelock_platform_interface 0.3.0 [flutter meta]
- wakelock_web 0.4.0 [flutter flutter_web_plugins js wakelock_platform_interface]
- wakelock_windows 0.2.1 [flutter wakelock_platform_interface win32]
- watcher 1.0.1 [async path]
- web_socket_channel 2.2.0 [async crypto stream_channel]
- win32 3.0.0 [ffi]
- xdg_directories 0.2.0+2 [meta path process]
- xml 6.1.0 [collection meta petitparser]
- yaml 3.1.1 [collection source_span string_scanner]


@felixgabler felixgabler added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Oct 3, 2022
@Lyokone Lyokone self-assigned this Oct 3, 2022
@darshankawar darshankawar added the triage Issue is currently being triaged. label Oct 3, 2022
@darshankawar
Copy link

Thanks for the report. Using code sample provided, I see same behavior as reported.

@darshankawar darshankawar added plugin: auth platform: ios Issues / PRs which are specifically for iOS. and removed Needs Attention This issue needs maintainer attention. triage Issue is currently being triaged. labels Oct 3, 2022
@Lyokone
Copy link
Contributor

Lyokone commented Oct 5, 2022

I've created an issue in the Firebase iOS SDK, this doesn't seems caused by FlutterFire: firebase/firebase-ios-sdk#10306

@Lyokone
Copy link
Contributor

Lyokone commented Oct 6, 2022

The behavior is currently not supported by the Firebase iOS SDK and is being worked on: firebase/firebase-ios-sdk#10068

@Lyokone
Copy link
Contributor

Lyokone commented Oct 28, 2022

The front end part is ready on the firebase iOS SDK and the backend part should land in the coming weeks so it should be fixed soon

@hamishjohnson
Copy link

I'm not sure if it's related but this seems to not request the email scope at all when using 'email' scope

@hamishjohnson
Copy link

hamishjohnson commented Dec 15, 2022

To add more context, when I add the email scope, the apple sign in modal does not seem to request that info as I don't get the 'this app wants you to share your email' and also does not give me the choice to hide my email. Then, when the registration succeeds, the account is a new one even if the email already exists in the backend - it is not merged with the old account.

On google sign in that works perfectly.

On the video below you can see how the flow works on my app for both apple and android - and you can see that on the apple sign in, the accounts are not merged (there's no existing data upon login) but for the google sign in, the accounts are merged (you can see the existing data)

RPReplay_Final1671084136.MP4

Here is the code I'm using for the two

  Future<UserCredential> signInWithGoogle() async {
    // Trigger the authentication flow
    try {
      // Once signed in, return the UserCredential
      final googleProvider = GoogleAuthProvider()..addScope('email');

      final result = await _auth.signInWithProvider(googleProvider);

      if (result.additionalUserInfo?.isNewUser == true) {
        _onRegister();
      }

      return result;
    } on PlatformException catch (e) {
      throw AppException.fromObject(e);
    }
  }

  Future<UserCredential> signInWithApple() async {
    try {
      final appleProvider = AppleAuthProvider()..addScope('email');

      final result = kIsWeb
          ? await _auth.signInWithPopup(appleProvider)
          : await _auth.signInWithProvider(appleProvider);

      if (result.additionalUserInfo?.isNewUser == true) {
        _onRegister();
      }

      return result;
    } on PlatformException catch (e) {
      throw AppException.fromObject(e);
    }
  }

@yazoonic
Copy link

yazoonic commented Jan 8, 2023

any update on this?

@Lyokone
Copy link
Contributor

Lyokone commented Jan 9, 2023

Still waiting on native: firebase/firebase-ios-sdk#10068

@pmcguane
Copy link

when will this be fixed apps are being declined because of this bug

@MahMoos
Copy link

MahMoos commented Feb 1, 2023

If you encounter this issue using the flutterfire-ui package, you should know it has been deprecated. Everything worked fine for me in the newly created packages firebase_ui_oauth and firebase_ui_oauth_apple and I can retrieve Apple display name using it.

@dnsflnv
Copy link

dnsflnv commented Feb 1, 2023

I have the same issue with firebase_ui_oauth_apple.

@MahMoos
Copy link

MahMoos commented Feb 1, 2023

Yes, that's right. I've missed up something in my app. There is still some issue in the backend.

@Flucadetena
Copy link

To add more context, when I add the email scope, the apple sign in modal does not seem to request that info as I don't get the 'this app wants you to share your email' and also does not give me the choice to hide my email. Then, when the registration succeeds, the account is a new one even if the email already exists in the backend - it is not merged with the old account.

On google sign in that works perfectly.

On the video below you can see how the flow works on my app for both apple and android - and you can see that on the apple sign in, the accounts are not merged (there's no existing data upon login) but for the google sign in, the accounts are merged (you can see the existing data)

RPReplay_Final1671084136.MP4
Here is the code I'm using for the two

  Future<UserCredential> signInWithGoogle() async {
    // Trigger the authentication flow
    try {
      // Once signed in, return the UserCredential
      final googleProvider = GoogleAuthProvider()..addScope('email');

      final result = await _auth.signInWithProvider(googleProvider);

      if (result.additionalUserInfo?.isNewUser == true) {
        _onRegister();
      }

      return result;
    } on PlatformException catch (e) {
      throw AppException.fromObject(e);
    }
  }

  Future<UserCredential> signInWithApple() async {
    try {
      final appleProvider = AppleAuthProvider()..addScope('email');

      final result = kIsWeb
          ? await _auth.signInWithPopup(appleProvider)
          : await _auth.signInWithProvider(appleProvider);

      if (result.additionalUserInfo?.isNewUser == true) {
        _onRegister();
      }

      return result;
    } on PlatformException catch (e) {
      throw AppException.fromObject(e);
    }
  }

This is actually the expected behavior. If you don't request "email" or "name" apple considers you don't need them and selects the default option for you. This means if the user has as default option to hide the email, it will hide it and that is why you are getting a new account on firebase. If you request the email and choose to hide the email, you will login into the same account on firebase.

In relation to the rest, I'm experiencing the same issue and Apple rejects my updates all the time cause of this problem. When will it be fixed?

Also in the Flutter, when you request in the scopes, you have to specify "email" and "name", but in the native scopes is "email" and "fullName". This should be the same as in the native code and well as documented somewhere. I could not find it anywhere.

Thanks for the work. Have a great day.

@ElixirMike
Copy link

I'm seeing this issue, how do I access the email or name ??

final appleProvider = AppleAuthProvider();
appleProvider.addScope('email');
appleProvider.addScope('name');
UserCredential userCredential = await FirebaseAuth.instance.signInWithProvider(appleProvider);
Then I try to access it via user object

print (userCredential.user?.email)

but it's always null. Also, I have gone into device settings and deleted my app from the AppleID login...so theoretically it should return email on first attempt.

@znromonk
Copy link

znromonk commented Feb 3, 2023

The issue is being resolved in the this PR.

@GustekDev
Copy link

Is there a version we can revert to in the meantime?

@avidan-chen
Copy link

My solution in the meantime:

  1. Add the sign_in_with_apple package.
  2. Add the following code:
final appleCredential = await SignInWithApple.getAppleIDCredential(
        scopes: [AppleIDAuthorizationScopes.email, AppleIDAuthorizationScopes.fullName],
);

// Create an `OAuthCredential` from the credential returned by Apple.
final oauthCredential = OAuthProvider("apple.com").credential(
idToken: appleCredential.identityToken,
);
final UserCredential userCredential = await FirebaseAuth.instance.signInWithCredential(oauthCredential);

if (userCredential.user?.displayName == null ||
            (userCredential.user?.displayName != null && userCredential.user!.displayName!.isEmpty)) {
          final fixDisplayNameFromApple = [
            appleCredential.givenName ?? '',
            appleCredential.familyName ?? '',
          ].join(' ').trim();
          await userCredential.user?.updateDisplayName(fixDisplayNameFromApple);
}
if (userCredential.user?.email == null ||
          (userCredential.user?.email != null && userCredential.user!.email!.isEmpty)) {
          await userCredential.user?.updateEmail(appleCredential.email ?? '');
}
// Now, FirebaseAuth.instance.currentUser contains the user with all the name and email updated.

Note that email and name won't always be provided by Apple - only for the first time the user logs in (hence the update is done only when data is actually present). I noticed you have to restart the device or wait a while to get this information again.

@mkobuolys
Copy link

mkobuolys commented Mar 2, 2023

I think the same issue persists on Android, too. Did anyone notice that?

@kirilllapshev
Copy link

@avidan-chen I've used your solution and it does work when it is the first time that the user logs in, as you mentioned. And my review still got rejected. Have you added any additional information for the reviewer to get your app approved?

@avidan-chen
Copy link

@kirilllapshev we got rejected because we were asking for the user's name and email (since we couldn't get it after the user logged in). Once we implemented this code, we removed the UI asking the user to input their name and email and Apple approved.

@mkobuolys
Copy link

@avidan-chen Removing this is not necessary. Based on Apple guidelines, prefilling the info for the user should be enough. What's not acceptable, is that you ask for the user name and email but, let's say, in the sign-up/login form you ask to fill in this info manually.

@kirilllapshev
Copy link

kirilllapshev commented Mar 4, 2023

@avidan-chen but do you ask for the user's name at some point? Or you just removed it from the app? Do you think by not asking for the user's name on the apple's signing modal and then renaming the name's label on the sign-up/login form inside you app from "Your name" to something else like "Name inside the app" would solve the problem?

@avidan-chen
Copy link

@kirilllapshev after first login, the app displays a profile page where the first name and last name is pre-populated. The user can change them if they wish. In the initial version, they were mandatory fields and were empty and that's why Apple rejected the app - they said we should fill it automatically for the user.
Once we modified the behavior as explained above, the app was approved.

@avidan-chen
Copy link

@mkobuolys you are correct, prefilling the info for the user was enough to get the app approved. Bad choice of words on my part - we didn't remove the UI completely, just pre-filled it.

@kirilllapshev
Copy link

Thank you for your solution @avidan-chen!

We were being rejected because although we were updating the displayName the name wasn't being filled in the initial form. After taking a careful look, we understood that the provider was only reading the firebase user once, and it was at the beginning, so the change was not being reflected in the UI. After noticing it we manually update the text control with the obtained with sign_in_with_apple and everything worked fine! 😁

@felixgabler
Copy link
Author

@Lyokone now that firebase/firebase-ios-sdk#10068 is merged, is this fixed?

@mkobuolys
Copy link

@felixgabler It's merged but not released yet.

@Lyokone
Copy link
Contributor

Lyokone commented Mar 13, 2023

Yes, it has to be released in an iOS Firebase SDK first (you can check on the release note page), then we have to do a new release of FlutterFire Core, including the native SDK. It'll probably be released in a couple of weeks.

@shurong-deng
Copy link

shurong-deng commented Mar 13, 2023

Because for AuthorizationCredentialAppleID

user data fields (first name, last name, email) will only be set if this is the initial authentication between the current app and Apple ID

so it is my solution:

String generateNonce([int length = 32]) {
  final charset =
      '0123456789ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvwxyz-._';
  final random = Random.secure();
  return List.generate(length, (_) => charset[random.nextInt(charset.length)])
      .join();
}

/// Returns the sha256 hash of [input] in hex notation.
String sha256ofString(String input) {
  final bytes = utf8.encode(input);
  final digest = sha256.convert(bytes);
  return digest.toString();
}

final rawNonce = generateNonce();
final nonce = sha256ofString(rawNonce);
FirebaseAuth auth = FirebaseAuth.instance;

    try {
      final appleCredential = await SignInWithApple.getAppleIDCredential(
        scopes: [
          AppleIDAuthorizationScopes.email,
          AppleIDAuthorizationScopes.fullName,
        ],
        nonce: nonce,
      );

      print(appleCredential);

      // Create an `OAuthCredential` from the credential returned by Apple.
      final oauthCredential = OAuthProvider("apple.com").credential(
        idToken: appleCredential.identityToken,
        rawNonce: rawNonce,
      );

      // Sign in the user with Firebase. If the nonce we generated earlier does
      // not match the nonce in `appleCredential.identityToken`, sign in will fail.
      final authResult = await auth.signInWithCredential(oauthCredential);

      final fixDisplayNameFromApple = [
        appleCredential.givenName ?? '',
        appleCredential.familyName ?? '',
      ].join(' ').trim();

      final userEmail = appleCredential.email ?? '';

      final firebaseUser = authResult.user;
      print(firebaseUser);
      if (fixDisplayNameFromApple.length > 0) {
        await firebaseUser?.updateDisplayName(fixDisplayNameFromApple);
      }

      if (userEmail.length > 0) {
        await firebaseUser?.updateEmail(userEmail);
      }
      await firebaseUser?.reload();

@mkobuolys
Copy link

This problem is already fixed in iOS SDK: https://firebase.google.com/support/release-notes/ios#10.7.0 Hopefully, we will get an SDK version bump soon 🤞

@Lyokone
Copy link
Contributor

Lyokone commented Mar 24, 2023

It should be fixed with the next release. PR is in review: #10652

@Arosf
Copy link

Arosf commented Apr 13, 2023

I noticed that the issue regarding missing displayName and email when signing in and linking with Apple on iOS was recently closed, but it doesn't seem to be fully resolved yet. I'm still experiencing the same issue and I'm wondering if there are any updates on this.

Firebase iOS SDK version 10.7.0 has been confirmed with firebase_core: 2.9.0 and firebase_auth: 4.4.0.

@dnsflnv
Copy link

dnsflnv commented Apr 13, 2023

Yes, the problem still exists.

@compcaddy
Copy link

Using Firebase 10.8.1 and problem persists

@sherkot
Copy link

sherkot commented Apr 19, 2023

I have same issue. Any update?

@firebase firebase locked and limited conversation to collaborators Apr 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
blocked: firebase-sdk platform: ios Issues / PRs which are specifically for iOS. plugin: auth resolution: fixed A fix has been merged or is pending merge from a PR. type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.