Flutter Apple Sign In - Empty Email

3,283

Solution 1

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.

Solution 2

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).

Share:
3,283
spookymodem
Author by

spookymodem

Updated on December 23, 2022

Comments

  • spookymodem
    spookymodem over 1 year

    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