invertase / react-native-apple-authentication

A React Native library providing support for Apple Authentication on iOS and Android.
Other
1.42k stars 223 forks source link

After Revoking Apple ID (Stop Using Apple ID) not getting full name and email on next login attempt #340

Open michaelbrant opened 10 months ago

michaelbrant commented 10 months ago

The FAQs say that in order to receive the full name and email again, you must revoke Apple ID access for the app. After logging out of the app, revoking Apple ID access (Settings > Apple ID > Sign-In & Security > Sign in with apple > My App > Stop Using Apple ID), and then logging in again, I'm still not seeing full name and email in the response. I was also expecting to be prompted to share/ hide my email address but that didn't pop up either.

Here is the code:

async function signInOrRegisterWithApple() {
  const appleAuthRequestResponse = await appleAuth.performRequest({
    requestedOperation: appleAuth.Operation.LOGIN,
    requestedScopes: [appleAuth.Scope.FULL_NAME, appleAuth.Scope.EMAIL],
  });

  const { identityToken, nonce, email, fullName } = appleAuthRequestResponse;

  if (identityToken) {
    const appleCredential = firebase.auth.AppleAuthProvider.credential(identityToken, nonce);

    const user = await firebase.auth().signInWithCredential(appleCredential);

    console.warn(`These values are empty: ${email} ${fullName?.givenName}`);
  } 
}

Other things I've tried:

  1. Made sure the order of requestedScopes had Full name first
  2. Uninstalled the app and reinstalled + revoke Apple ID access while uninstalled
  3. Posted in Apple Community
  4. I've tried to revoke the token, at first I was getting[Error: [auth/invalid-credential] The supplied auth credential is malformed or has expired.] but realized this was because I was using firebase local auth emulator. After switching to the hosted firebase auth, revokeToken did work successfully, however, the main problem still persists.
async function revokeSignInWithAppleToken() {
  const { authorizationCode } = await appleAuth.performRequest({
    requestedOperation: appleAuth.Operation.REFRESH,
  });

  if (!authorizationCode) {
    throw new Error("Apple Revocation failed - no authorizationCode returned");
  }

  // Revoke the token
  return auth().revokeToken(authorizationCode);
}
mikehardy commented 8 months ago

Unexpected. Do you have version information of all the components of the system under test (device model number, device operating system, relevant package versions from package.json, xcode version etc)? https://stackoverflow.com/help/how-to-ask

The FAQ you list was developed via experience / test results from users of the library. I personally did not do the testing or observe the results so I don't have the experience to say if it used to work correctly or not. I also do not have time to do the testing now, with apologies.

I'm open to any PR either updating documentation or altering code as needed depending on what you learn via testing and/or any responses you get from the Apple discussions

wordisthebird commented 7 months ago

any update on this?

MayurMax4 commented 7 months ago

hi team, we are also getting the same issue, where email is also not coming after successful authentication. Currently using the version 2.3.0. Any suggestion will be helpful..

azulay7 commented 6 months ago

I waiting also for some solution. appleAuth.performRequest response does not contains any personal value

siquick commented 6 months ago

Also suddenly getting this issue of no displayName or email. Using version 2.3.0 of library.

Have tried the following:

Email address is now also not being stored in Firebase.

Code for Apple Sign In

const appleAuthRequestResponse = await appleAuth.performRequest({
      requestedOperation: appleAuth.Operation.LOGIN,
      requestedScopes: [appleAuth.Scope.FULL_NAME, appleAuth.Scope.EMAIL],
});
turkmenkaan commented 6 months ago

We're having the same issue here. Any update would be very appreciated

turkmenkaan commented 6 months ago

After checking Apple Settings > Sign In, we noticed that the token was not actually revoked in the first place. That's probably why you're not receiving user information upon next login. Not sure what's wrong with the revokeToken method though, it seems to not resolve the promise.

siquick commented 6 months ago

I have managed to get the Apple token revoking by following these setup instructions closely and using this function.

export const deleteAppleUser = async (): Promise<ReturnType> => {
    try {
        // Get an authorizationCode from Apple
        const { authorizationCode } = await appleAuth.performRequest({
            requestedOperation: appleAuth.Operation.REFRESH,
        });

        // Ensure Apple returned an authorizationCode
        if (!authorizationCode) {
            throw new Error("Apple Revocation failed - no authorizationCode returned");
        }

        const result = await auth().revokeToken(authorizationCode);

        return { result, error: null };
    } catch (error) {
        Sentry.captureException(error);
        return { result: null, error };
    }
};

The problem I'm having now is that, even for new users, I am no longer getting the users name, only the email address.

This is my JS function for Sign In


async function onAppleButtonPress() {
        try {
            // Start the sign-in request
            const appleAuthRequestResponse = await appleAuth.performRequest({
                requestedOperation: appleAuth.Operation.LOGIN,
                requestedScopes: [appleAuth.Scope.EMAIL, appleAuth.Scope.FULL_NAME],
            });

            // Ensure Apple returned a user identityToken
            if (!appleAuthRequestResponse.identityToken) {
                throw new Error("Apple Sign-In failed - no identify token returned");
            }

            // Create a Firebase credential from the response
            const { identityToken, nonce } = appleAuthRequestResponse;
            const appleCredential = auth.AppleAuthProvider.credential(identityToken, nonce);

            // Sign the user in with the credential
            return await auth().signInWithCredential(appleCredential);

        } catch (error) {
            console.error(error);
            return { result: null, error };
    }
Daniel3711997 commented 5 months ago

The issue still persist

thangpaisen commented 5 months ago

I also encountered this problem in version 2.3.0 Using version 2.2.2 the problem was resolved

sqpollen commented 4 months ago

I am now getting the fullName after the user revokes their access. However, it does not get saved to the user record in Firebase unless I systematically update the profile. Is there a better way to do this than calling auth().currentUser.updateProfile?


const appleAuthRequestResponse = await appleAuth.performRequest({
    requestedOperation: appleAuth.Operation.LOGIN,
    requestedScopes: [appleAuth.Scope.FULL_NAME, appleAuth.Scope.EMAIL],
});

// Ensure Apple returned a user identityToken
if (!appleAuthRequestResponse.identityToken) {
throw new Error("Apple Sign-In failed - no identify token returned");
}

// Create a Firebase credential from the response
const { identityToken, nonce, fullName } = appleAuthRequestResponse;
const appleCredential = auth.AppleAuthProvider.credential(identityToken, nonce);

const userCredential = await auth().signInWithCredential(appleCredential);

//Update the profile with the fullName
if (fullName) {
  const update = {
      displayName: `${fullName.givenName} ${fullName.familyName}`,
      photoURL: "",
  };
  await auth().currentUser.updateProfile(update);

}
moustafahelmi96 commented 4 months ago

have the same issue

MrNapcae commented 4 months ago

have the same issue

aboveStars commented 3 months ago

Having the same issue. Edit: I realized that this issue only exists on iOS Simulators not on real devices.

nroV commented 1 month ago

any solution?