8

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.

gg11
  • 570
  • 6
  • 16

1 Answers1

4

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; }
    
CharlesC
  • 1,010
  • 10
  • 24
  • Is there no way to get the redirect url to work without using whatever "Glitch" is? – Jonas Zebari Nov 03 '20 at 00:49
  • 1
    @JonasZebari Sure you can, Glitch just a free host service you can leverage, But you do have some sort of service to handle the redirect tho. – CharlesC Nov 07 '20 at 04:09