androidflutterfirebase-authenticationsign-in-with-apple

Android Sign in with apple and firebase flutter


I'm using sign_in_with_apple and I've got the signin working for ios but the android component is not working.

I've had a look through the docs and issues where this is asked but there are no clear answers. https://github.com/aboutyou/dart_packages/tree/master/packages/sign_in_with_apple

I'm stuck on the part of the docs for this plugin that say:

On the Sign in with Apple callback on your sever (specified in WebAuthenticationOptions.redirectUri), redirect safely back to your Android app using the following URL:

intent://callback?${PARAMETERS_FROM_CALLBACK_ BODY}#Intent;package=YOUR.PACKAGE.IDENTIFIER;scheme=signinwithapple;end

The PARAMETERS FROM CALLBACK BODY should be filled with the urlencoded body you receive on the endpoint from Apple's server, and the package parameter should be changed to match your app's package identifier (as published on the Google Play Store). Leave the callback path and signinwithapple scheme untouched.

Furthermore, when handling the incoming credentials on the client, make sure to only overwrite the current (guest) session of the user once your own server have validated the incoming code parameter, such that your app is not susceptible to malicious incoming links (e.g. logging out the current user).

The part that says: The PARAMETERS FROM CALLBACK BODY should be filled with the urlencoded body you receive on the endpoint from Apple's server. I'm unsure about how to get this and correctly format the PARAMATERS_FROM_CALLBACK_BODY part of the redirectURL to get this working for Android.


Solution

  • I was having exactly the same question and I actually opened up an issue on their repo yesterday.

    I'm not sure if you are trying to set up your own backend server for callback or not, but to answer your question, the part you were having issue to understand is only apply for someone who need to implement their own API for call back.

    I did get the Apple Sign In for Android to work(via web browser auth) with the following steps:

    Note: Since you already got iOS part working, so I assume you got the basic configure taken care of already.

    1. Set up the glitch.com service based off their document, this part is easy to follow.

    2. And then you want to implement your signInWithApple call as the following reference Note: SERVER_AS_PER_THE_DOCS need update according to your glich service.

      Future<FirebaseUser> signInWithApple() async {
      var redirectURL = "https://SERVER_AS_PER_THE_DOCS.glitch.me/callbacks/sign_in_with_apple";
      var clientID = "AS_PER_THE_DOCS";
      final appleIdCredential = await SignInWithApple.getAppleIDCredential(
          scopes: [
            AppleIDAuthorizationScopes.email,
            AppleIDAuthorizationScopes.fullName,
          ],
          webAuthenticationOptions: WebAuthenticationOptions(
              clientId: clientID,
              redirectUri: Uri.parse(
                  redirectURL)));
      final oAuthProvider = OAuthProvider(providerId: 'apple.com');
      final credential = oAuthProvider.getCredential(
        idToken: appleIdCredential.identityToken,
        accessToken: appleIdCredential.authorizationCode,
      );
      final authResult =
          await SignInUtil.firebaseAuth.signInWithCredential(credential);
      return authResult.user; }