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] Firebase user displayName not filled from Apple Sign-in credentials #7274

Closed
boris-hocde opened this issue Oct 31, 2021 · 5 comments
Labels
platform: ios Issues / PRs which are specifically for iOS. plugin: auth resolution: invalid This doesn't seem right and might not belong here. type: bug Something isn't working

Comments

@boris-hocde
Copy link

Bug report

Hi,
I'm facing an issue with Apple Sign-in.
With the documented method, the user given name and family name are not copied from Apple credentials to the Firebase user.
This results in Apple rejecting app submissions because of the guideline 5.1.1:

Your app requires users to provide their name and/or email address after using Sign in with Apple.
Sign in with Apple is designed to be a self-contained, all-in-one login system.

Steps to reproduce

  1. Have a Firebase project with an iOS app ready to use the Apple sign-in capability
  2. Enable Firebase auth with Apple provider
  3. Run a Flutter app on an iOS device with an identity that can be used for Apple Sign-in (2FA + iCloud)
  4. In the Flutter app, run the documented method to sign-in with Apple
  5. Once the user is authenticated, try to access their displayName

Expected behavior

We should find back in displayName what the user provided as given name and family name while granting the Apple ID permission. "Timm" in this example.

Sample project

https://gitlab.com/boris.hocde1/authlink

  • The snack bar shows that appleCredential contains the given name & family name (see here)
  • The name displayed on screen shows that the Firebase user's displayName is null (see here)

Video showing the issue for this sample app


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, 2.5.3, on macOS 11.6 20G165 darwin-arm, locale en-FR)
[✗] Android toolchain - develop for Android devices
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.

[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[!] Android Studio (not installed)
[✓] Connected device (2 available)

! Doctor found issues in 2 categories.

Flutter dependencies

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

Click To Expand
Dart SDK 2.14.4
Flutter SDK 2.5.3
authlink 1.0.0+1

dependencies:
- crypto 3.0.1 [collection typed_data]
- firebase_auth 3.1.4 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 1.8.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_dynamic_links 2.0.11 [firebase_core flutter]
- flutter 0.0.0 [characters collection meta typed_data vector_math sky_engine]
- sign_in_with_apple 3.2.0 [flutter meta]

dev dependencies:
- flutter_lints 1.0.4 [lints]
- flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters charcode collection matcher meta source_span stream_channel string_scanner term_glyph typed_data]

transitive dependencies:
- async 2.8.1 [collection meta]
- boolean_selector 2.1.0 [source_span string_scanner]
- characters 1.1.0
- charcode 1.3.1
- clock 1.1.0
- collection 1.15.0
- fake_async 1.2.0 [clock collection]
- firebase_auth_platform_interface 6.1.2 [firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 3.1.3 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser intl js meta]
- firebase_core_platform_interface 4.0.1 [collection flutter meta plugin_platform_interface]
- firebase_core_web 1.1.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- flutter_web_plugins 0.0.0 [flutter js characters collection meta typed_data vector_math]
- http_parser 4.0.0 [charcode collection source_span string_scanner typed_data]
- intl 0.17.0 [clock path]
- js 0.6.3
- lints 1.0.1
- matcher 0.12.10 [stack_trace]
- meta 1.7.0
- path 1.8.0
- plugin_platform_interface 2.0.2 [meta]
- sky_engine 0.0.99
- source_span 1.8.1 [collection path term_glyph]
- stack_trace 1.10.0 [path]
- stream_channel 2.1.0 [async]
- string_scanner 1.1.0 [charcode source_span]
- term_glyph 1.2.0
- test_api 0.4.2 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher]
- typed_data 1.3.0 [collection]
- vector_math 2.1.0

@boris-hocde boris-hocde added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Oct 31, 2021
@darshankawar darshankawar added the triage Issue is currently being triaged. label Nov 2, 2021
@darshankawar
Copy link

I noted this behavior / issue while verifying the other issue, #7272, so confirming that is replicable on latest stable.

stable flutter doctor -v
[✓] Flutter (Channel stable, 2.5.3, on Mac OS X 10.15.4 19E2269 darwin-x64,
    locale en-GB)
    • Flutter version 2.5.3 at /Users/dhs/documents/fluttersdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18116933e7 (2 days ago), 2021-10-15 10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

[✓] Android toolchain - develop for Android devices (Android SDK version 30)
    • Android SDK at /Users/dhs/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = /Users/dhs/Library/Android/sdk
    • Java binary at: /Users/dhs/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/202.7486908/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.    

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.3, Build version 12C33
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Users/dhs/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/202.7486908/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
      1.8.0_242-release-1644-b3-6915495)        

[✓] VS Code (version 1.57.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.21.0

[✓] Connected device (4 available)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 93.0.4577.82


• No issues found!

@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 Nov 2, 2021
@tushar0518
Copy link

have you found any solution @boris-hocde?

@boris-hocde
Copy link
Author

@tp-coderbabu Yes, you need to set the Firebase display name from AuthorizationCredentialAppleID. Something like this:

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

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

// ... once the authentication is complete

if (fixDisplayNameFromApple != null && firebaseAuthUser.displayName == null) {
  await firebaseAuthUser.updateDisplayName(_fixDisplayNameFromApple);
  firebaseAuthUser.reload();
}

@tushar0518
Copy link

@tp-coderbabu Yes, you need to set the Firebase display name from AuthorizationCredentialAppleID. Something like this:

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

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

// ... once the authentication is complete

if (fixDisplayNameFromApple != null && firebaseAuthUser.displayName == null) {
  await firebaseAuthUser.updateDisplayName(_fixDisplayNameFromApple);
  firebaseAuthUser.reload();
}

Thank you so much @boris-hocde

@russellwheatley
Copy link
Member

Hey @boris-hocde, thanks for providing a solution to the issue. This is an ongoing problem on the firebase-ios-sdk which you can track here. FlutterFire simply wraps around this SDK so it needs to be fixed upstream.

@darshankawar darshankawar added the resolution: invalid This doesn't seem right and might not belong here. label Apr 5, 2022
@firebase firebase locked and limited conversation to collaborators May 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform: ios Issues / PRs which are specifically for iOS. plugin: auth resolution: invalid This doesn't seem right and might not belong here. type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants