Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: The supplied auth credential is malformed, has expired or is not currently supported. #33

Closed
mohitbhansali opened this issue Jan 24, 2020 · 13 comments

Comments

@mohitbhansali
Copy link

mohitbhansali commented Jan 24, 2020

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?

@mikehardy
Copy link
Collaborator

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

@mcmillion
Copy link

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.

@mohitbhansali
Copy link
Author

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

@mikehardy
Copy link
Collaborator

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

@imanodaysoffdotcom
Copy link

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

@mikehardy
Copy link
Collaborator

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 firebase/firebase-ios-sdk#4434 (comment)

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

@mohitbhansali
Copy link
Author

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

@ato-henok
Copy link

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 => {});}

@mikehardy
Copy link
Collaborator

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

Perhaps it's bundle IDs or similar

@sidVaidya
Copy link

sidVaidya commented Jul 21, 2020

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.

@rnnyrk
Copy link

rnnyrk commented Jul 27, 2020

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

@isaactan001
Copy link

I am implementing sign in with Apple. I can successfully see the Apple login page. I key in the correct credentials. It should be able to sign in/sign up to the firebase based on the returned value from Apple.

However I am getting this error Error: The supplied auth credential is malformed, has expired or is not currently supported. Something must be wrong at the firebase side? You may refer to the onPressAppleLogin function below on the logic. Many thanks!

What I have done:

In Firebase

  1. Authentication with Sign-in provider Apple enabled
  2. My service id is co.myexampleapp.signinwithapple
  3. My authorization callback is https://my-example-app.firebaseapp.com/__/auth/handler

In developer.apple.com

  1. I created a service id co.myexampleapp.signinwithapple with the service Sign In with Apple enabled
  2. I added my-example-app.firebaseapp.com for the Domain and https://my-example-app.firebaseapp.com/__/auth/handler in the Return URLs

My React Native source code

import { appleAuthAndroid } from '@invertase/react-native-apple-authentication';
import firebase from 'react-native-firebase'

getRandomString = (length: any) => {
    let randomChars =
        'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
    let result = ''
    for (let i = 0; i < length; i++) {
        result += randomChars.charAt(Math.floor(Math.random() * randomChars.length))
    }
    return result
}

onPressAppleLogin = async () => {
    const rawNonce = this.getRandomString(20);
    const state = this.getRandomString(20)

    appleAuthAndroid.configure({
        clientId: 'co.myexampleapp.signinwithapple',
        redirectUri: 'https://my-example-app.firebaseapp.com/__/auth/handler',
        responseType: appleAuthAndroid.ResponseType.ALL,
        scope: appleAuthAndroid.Scope.ALL,
        nonce: rawNonce,
        state,
    });

    const response = await appleAuthAndroid.signIn();

    const appleCredential = await firebase.auth.AppleAuthProvider.credential(response.id_token, rawNonce)

    const appleUserCredential = await firebase.auth().signInWithCredential(appleCredential) // error happens here!
}

@htshnr
Copy link

htshnr commented Aug 22, 2024

Your bundle ID should match and be the same everywhere - in xcode, app.json, apple developer console (services and keys enabled for that bundle ID), and in your firebase config.

Once you modify your bundle ID on Firebase, you'll get a new GoogleService-Info.plist file. Replace your old .plist file in your local project folder with it. If you're still getting an error, go into your ios subfolder and check the cached copy of the .plist file there, you may have to change that as well manually if it hasn't updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants