Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Apple Sign In - Empty Email

I am trying to add "Apple Sign In" to my Flutter iOS app using the apple_sign_in package.

The code is mostly working. My problem is that the call to _firebaseAuth.signInWithCredential(credential) is creating a firebase account that has a null identifier (please see screenshot below).

One weird thing about this is that when the user selects the option to share their email address when signing up, result.credential.email contains the user's email address after the call to AppleSignIn.performRequests(). So I'm really puzzled as to why the user's email is not being used as the identifier when the account is created in Firebase.

  Future<FirebaseUser> signInWithApple() async {
    final AuthorizationResult result = await AppleSignIn.performRequests([
      AppleIdRequest(requestedScopes: [Scope.email, Scope.fullName])
    ]);

    switch (result.status) {
      case AuthorizationStatus.authorized:
        final AppleIdCredential appleIdCredential = result.credential;

        OAuthProvider oAuthProvider =
        new OAuthProvider(providerId: "apple.com");

        final AuthCredential credential = oAuthProvider.getCredential(
          idToken: String.fromCharCodes(appleIdCredential.identityToken),
          accessToken: String.fromCharCodes(
              appleIdCredential.authorizationCode),
        );

        await _firebaseAuth.signInWithCredential(credential);
        return _firebaseAuth.currentUser();

        break;

      case AuthorizationStatus.error:
        print('Sign in failed: ${result.error.localizedDescription}');
        break;

      case AuthorizationStatus.cancelled:
        print('User cancelled');
        break;
    }

    return null;
  }

enter image description here

like image 782
spookymodem Avatar asked Jul 30 '20 14:07

spookymodem


People also ask

How do I stop Apple from hiding my email?

Go to Settings > [your name] > iCloud > Hide My Email, then do any of the following: Create a Hide My Email address: Tap Create New Address, then follow the onscreen instructions. Deactivate a Hide My Email address: Tap an address (below Create New Address), then tap Deactivate Email Address.

How do I stay signed in to flutter?

There are many ways of keeping user signed-in to a flutter application. In this tutorial we going to use firebase Auth method authStateChanges(). Firebase Auth enables you to subscribe in realtime to this state via a Stream .


2 Answers

I believe this is working as intended;

Apple only returns the full name and email on the first login on the device for your app, it will return null values for these on any login after that. My guess is that you've signed in previously and then tried to sign-in again via a new Firebase Auth user and the Name/Email is no longer available at that point.

For testing purposes, to receive these again; go to your device settings; Settings > Apple ID, iCloud, iTunes & App Store > Password & Security > Apps Using Your Apple ID, tap on your app and tap Stop Using Apple ID. You can now sign-in again and you'll receive the full name and email again.

This is how Apple has designed their API - so it's recommended that you store these elsewhere on your app, e.g. using the shared_preferences plugin - so that you consistently have access to them when required.

like image 196
Tanvir Ahmed Avatar answered Oct 18 '22 22:10

Tanvir Ahmed


The problem is iOS 13.6 in 13.5 I got Name, email, token, id. but in iOS 13.6 only return de user ID. I use the sign_in_with_apple dependency (https://pub.dev/packages/sign_in_with_apple).

like image 35
Julio Heberto Gonzalez Morales Avatar answered Oct 18 '22 21:10

Julio Heberto Gonzalez Morales