flutterfirebase-authenticationsign-in-with-apple

FirebaseAuth: "The audience in ID Token does not match the expected audience" when I tried sign-in with Apple ID on Android Device


I'm facing this issue after I entered any Apple ID account and press "Continue" using an Android device:

FirebaseAuthException ([firebase_auth/invalid-credential] The supplied auth credential is malformed or has expired. [The audience in ID Token [My ServiceID] does not match the expected audience. ])

If I use an iPhone, it works successfully, the problem is after I entered any Apple ID account in the AppleId web view using any Android device.

here is my code:

static Future<UserCredential> signInWithApple() async {
    final appleCredential = await SignInWithApple.getAppleIDCredential(
      scopes: [
        AppleIDAuthorizationScopes.email,
        AppleIDAuthorizationScopes.fullName,
      ],
      webAuthenticationOptions: WebAuthenticationOptions(
          clientId: FIREBASE_BUNDLE_ID //I have this data according to package documentation
          redirectUri: Uri.parse(
              'https://MI_PROJECT_ID.cloudfunctions.net/handleAppleSignIn')),
    );

    final oauthCredential = OAuthProvider('apple.com').credential(
      idToken: appleCredential.identityToken,
      accessToken: appleCredential.authorizationCode,
    );

    final UserCredential appleUser =
        await FirebaseAuth.instance.signInWithCredential(oauthCredential);

    return appleUser;
  }

Im using sign_in_with_apple: ^4.3.0 , firebase_core: ^2.3.0 and firebase_auth: ^4.4.0

I have my project registered in firebase and developer.apple.com, the Apple provider as Sign-In provider also OAuth 2.0 Client IDs registration and all the setup of the https://pub.dev/packages/sign_in_with_apple package, the intent://callback?${PARAMETERS FROM CALLBACK BODY}#Intent;package=YOUR.PACKAGE.IDENTIFIER;scheme=signinwithapple;end I also configured the Apple ServiceId with the return URL for using Firebase Cloud Functions

If I use the Apple Id sign in option on any Android device, is it considered a Web method and do I need to use FirebaseAuth.instance.signInWithPopup() as the page https://firebase.google.com/docs/auth/flutter/federated-auth?hl=en&authuser=0#android_1 says?


Solution

  • Solved:

    I got confused when putting the Apple OAuth client ID of the Google Cloud credentials instead of the correct Service ID of the Sign with Apple setup in dev apple page.