Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 914
Gerry Avatar asked Jul 08 '20 23:07

Gerry


People also ask

Does sign in with Apple work on Android?

You can sign in to Apple Music on Android, or sign in to the Apple TV app on your smart TV or streaming device.

How do I use Apple Login on Flutter?

If you are using Android Studio, right-click on the ios folder, find Flutter and then click on the Open iOS module in Xcode. Now, click on the + Capability (just below the Signing and Capabilities tab) find the Sign in with Apple, and double click to add.

How do I get my Apple ID to Flutter?

If you want to enable Apple Sign In on both iOS and Android, you should use sign_in_with_apple instead. This will work on both platforms, but the integration will require some server-side code.


1 Answers

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; }
    
like image 164
CharlesC Avatar answered Sep 20 '22 12:09

CharlesC