React-native-apple-authentication: Error: The supplied auth credential is malformed, has expired or is not currently supported.

Created on 24 Jan 2020  路  11Comments  路  Source: invertase/react-native-apple-authentication

Xcode Version: 11.3.1
React Native Version: 0.60.3
@invertase/react-native-apple-authentication version: 0.1.1
React Native Firebase: 5.6.0

import appleAuth, {
  AppleAuthRequestOperation,
  AppleAuthRequestScope,
  AppleAuthError
} from "@invertase/react-native-apple-authentication";
import firebase, { AuthCredential } from "react-native-firebase";

const loginWithApple = (): Promise<AuthCredential> => {
  return new Promise(async (resolve, reject) => {
    try {
      const appleAuthRequestResponse = await appleAuth.performRequest({
        requestedOperation: AppleAuthRequestOperation.LOGIN,
        requestedScopes: [
          AppleAuthRequestScope.EMAIL,
          AppleAuthRequestScope.FULL_NAME
        ]
      });

      const {
        user: newUser,
        email,
        nonce,
        identityToken
      } = appleAuthRequestResponse;

      if (identityToken) {
        const appleCredential = firebase.auth.AppleAuthProvider.credential(
          identityToken,
          nonce
        );
        resolve(appleCredential);
      } else {
        // no token - failed sign-in?
      }
      console.warn(`Apple Authentication Completed, ${newUser}, ${email}`);
    } catch (error) {
      if (error.code === AppleAuthError.CANCELED) {
        // eslint-disable-next-line no-console
        console.warn("User canceled Apple Sign in.");
      } else {
        // eslint-disable-next-line no-console
        console.error(error);
      }
      reject(error);
    }
  });
};

export default loginWithApple;

I am passing the credentials in the firebase auth:

firebaseUser = await firebase.auth().signInWithCredential(credential);

Getting the following error:

Error: The supplied auth credential is malformed, has expired or is not currently supported at createErrorFromData

Let me know what am I missing here?

waiting for feedback

Most helpful comment

@henokweldemicael sounds like a firebase issue, not apple. If apple is working this module is likely fine

Perhaps it's bundle IDs or similar

All 11 comments

How did it work when you cloned the repo and tried the example here?

I'm suddenly running into this as well after having the sign in working fine. I can remove the auth from the apple account and signing in again restores it I get credentials back from Apple, but I get the same error when trying to sign in with firebase.

@mikehardy It's not working with a specific version of react-native-firebase i.e. 5.6.0. Apple sign-in is working with "6.2.0". But I ran into another problem wherein re-login isn't working. I am getting the following error:

Duplicate credential received. Please try again with a new credential.

It's working fine with v5.6.0. The PR that implemented it was mine. I just tested it in my app today.

Try making sure your app package name and firebase package names matches...

Check your bundle id in the GoogleService-Info.plist file inside on your IOS project
Check the settings in the Firebase Console under the section your apps.

Could also try generating a new GoogleService-Info.plist file to be safe

@mohitbhansali

There is an upstream issue (you can search the firebase-ios-sdk github repo) indicating that because the nonce must be unique each time, you have to make fresh auth requests each time if you are re-authenticating or upgrading from anonymous. I think they updated the documentation just recently https://github.com/firebase/firebase-ios-sdk/issues/4434#issuecomment-564776016

You might get more information from the raw Xcode or console error logs

Thank you everyone for the response. I have upgraded it to version "6.2.0" and it's working.

I got the latest version of everything and this error is happening. Any ideas? We are getting authentication with a token from Apple, but the issue appears to be on the Firebase side. The auth().signInWithCredential function is throwing the error.

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

  // Ensure Apple returned a user identityToken
  if (!appleAuthRequestResponse.identityToken) {
    this.setState({ errorMessage: "Error signing in with Apple." });
  }
  // Create a Firebase credential from the response
  const { identityToken, nonce } = appleAuthRequestResponse;
  const appleCredential = firebase.auth.AppleAuthProvider.credential(
    identityToken,
    nonce
  );

  if (appleCredential) {
    auth()
      .signInWithCredential(appleCredential)
      .then(async userInfo => {});}

@henokweldemicael sounds like a firebase issue, not apple. If apple is working this module is likely fine

Perhaps it's bundle IDs or similar

hey were you able to solve the issue? @heno

I got the latest version of everything and this error is happening. Any ideas? We are getting authentication with a token from Apple, but the issue appears to be on the Firebase side. The auth().signInWithCredential function is throwing the error.

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

  // Ensure Apple returned a user identityToken
  if (!appleAuthRequestResponse.identityToken) {
    this.setState({ errorMessage: "Error signing in with Apple." });
  }
  // Create a Firebase credential from the response
  const { identityToken, nonce } = appleAuthRequestResponse;
  const appleCredential = firebase.auth.AppleAuthProvider.credential(
    identityToken,
    nonce
  );

  if (appleCredential) {
    auth()
      .signInWithCredential(appleCredential)
      .then(async userInfo => {});}

hey were you able to solve the issue i am also getting the same error.

Like @imanodaysoffdotcom suggested I indeed had a mismatch in my Firebase app name (also in GoogleService-Info.plist) and Apple bundle id. After matching those it worked :)

Was this page helpful?
0 / 5 - 0 ratings