Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter App - Sign In with Apple not returning Name to Firebase. Why?

I have a Flutter app that uses the sign in with Apple package with Firebase, however I'm unable to return the user's name. How can I return the Apple user name? Any help would be appreciated.

Here is the code I have so far. Any thoughts to what I'm missing?


Future<UserCredential> appleSignIn() async {
  if (kIsWeb) {
    final provider = OAuthProvider("apple.com")
      ..addScope('email')
      ..addScope('name');

    // Sign in the user with Firebase.
    return await FirebaseAuth.instance.signInWithPopup(provider);
  }

  final rawNonce = generateNonce();
  final nonce = sha256ofString(rawNonce);

  // Request credential for the currently signed in Apple account.
  final appleCredential = await SignInWithApple.getAppleIDCredential(
    scopes: [
      AppleIDAuthorizationScopes.email,
      AppleIDAuthorizationScopes.fullName,
    ],
    nonce: nonce,
  );

  // 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.
  return await FirebaseAuth.instance.signInWithCredential(oauthCredential);
}

Future<User?> signInWithApple(BuildContext context) =>
    signInOrCreateAccount(context, appleSignIn, 'APPLE');
like image 538
xG00gle Avatar asked Nov 27 '25 04:11

xG00gle


1 Answers

Try revoking sign-in access for the app in your sign-in with apple settings

You can do this by going to settings -> your apple id -> sign in & security -> sign in with apple and selecting the app and tapping Stop using Apple ID

If anyone else comes to this question looking for how to get name & email with the default Firebase auth plugin and not sign_in_with_apple, you need to add scopes:

final appleProvider = AppleAuthProvider();
appleProvider.addScope("email");
appleProvider.addScope('name');
like image 145
Mans Avatar answered Nov 30 '25 00:11

Mans



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!