Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppleSignIn (with Firebase & Expo) working locally but not on standalone

I implemented the signinWithApple button on my Expo app, and it's working perfectly locally when i use the host.exp.Exponent on Services ID in Firebase authentification tab for Apple Sign in.

But when I create a standalone app, and I test it with TestFlight, it doesn't work anymore whether I use host.exp.Exponent, nothing, or my specific app service ID on Services ID.

What am I missing here?

MY CODE :

handleApple = async () => {
    const csrf = Math.random().toString(36).substring(2, 15);
    const nonce = Math.random().toString(36).substring(2, 10);

    try {
      const appleCredential = await AppleAuthentication.signInAsync({
        requestedScopes: [
          AppleAuthentication.AppleAuthenticationScope.FULL_NAME,
          AppleAuthentication.AppleAuthenticationScope.EMAIL
        ],
        state: csrf,
        nonce: nonce
      });

      const {
        identityToken,

        fullName,
        email
      } = appleCredential;

      if (identityToken) {
        // login with credential
          const provider = new firebase.auth.OAuthProvider("apple.com");
          const credential = provider.credential({
            idToken: identityToken,
            rawNonce: nonce,

          });

          await firebase.auth().signInWithCredential(credential).then(user => {
          ...

EDIT :

I managed to make it work by using my bundle identifier (which is also my app id) on the Service ID field in firebase.

Error code :

Error: The audience in ID Token [##.app-videos] does not match the expected audience ##.signin.

But now the sign in with Apple on my website breaks. I manage to make it work when I change the Service Id field to my specific app service ID (found in Identifiers > Services IDs).

So i'm stuck with an app that requires something and a website that requires an other. Why is that?

Should I do something specific when I rebuild my app so that the changes that I made to mu identifiers are taken into account? I'm using this, is it not enough?

expo build:ios --clear-provisioning-profile

like image 974
Ali Chahat Avatar asked Jan 25 '20 23:01

Ali Chahat


People also ask

Can we use Apple Sign in in Android?

You can let your users authenticate with Firebase using their Apple ID by using the Firebase SDK to carry out the end-to-end OAuth 2.0 sign-in flow. Important: To sign in with an Apple account, users must: Have an Apple ID with two-factor authentication (2FA) enabled.

How do I enable Apple Sign in?

Go to Settings > Passwords. Under Security Recommendations, tap an app or website name. * Tap Use Sign in with Apple, then follow the onscreen steps.

Can iOS apps use Firebase?

Go to the Firebase console. In the center of the project overview page, click the iOS+ icon to launch the setup workflow. If you've already added an app to your Firebase project, click Add app to display the platform options. Enter your app's bundle ID in the bundle ID field.

What is Idtoken in Firebase?

If your Firebase client app communicates with a custom backend server, you might need to identify the currently signed-in user on that server. To do so securely, after a successful sign-in, send the user's ID token to your server using HTTPS.


1 Answers

I had the same problem and should solve it in the following way.

You must re-create GoogleService-info.plist in the Firebase console with the same bundleId as in the project in Xcode.

like image 71
Carlos A Rodriguez Avatar answered Oct 14 '22 06:10

Carlos A Rodriguez