supabase / supabase-flutter

Flutter integration for Supabase. This package makes it simple for developers to build secure and scalable products.
https://supabase.com/
MIT License
662 stars 155 forks source link

How do we sign in with Apple on Flutter for Android? #811

Closed elliottetzkorn closed 3 months ago

elliottetzkorn commented 5 months ago

This flow would really benefit from documentation. Following the guide here is very confusing with Supabase. Specifically documentation around how to handle callback URL's would be appreciated.

It seems like we are supposed to implement this callback

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

instead of the supa recommended:

io.supabase.yourapp://login-callback/

any insight here?

dshukertjr commented 5 months ago

Thanks for pointing this out. We certainly lack documentation for Apple sign-in on Android.

We currently recommend using signInWithOAuth() method to perform Apple sign-in on Android instead of using the sign_in_with_apple package. Will make sure this is clear on the docs as well as our readme.

mikkomcmenamin commented 4 months ago

I'm currently struggling with this too. Even when using signInWithOAuth() I can't seem to get the redirect link to work.

dshukertjr commented 4 months ago

@mikkomcmenamin Can you follow the instructions here and see if you can make it work? https://supabase.com/docs/guides/auth/social-login/auth-apple?platform=flutter#apple-sign-in-on-android-web-windows-and-linux

dshukertjr commented 3 months ago

I'm going to close this one as we have documentation on how to implement Apple sign-in on Android.

https://supabase.com/docs/guides/auth/social-login/auth-apple?platform=flutter#apple-sign-in-on-android-web-windows-and-linux

formalpair commented 2 months ago

Hey Tyler, Supabase team

Unfortunately I'm also struggling to handle properly the login on android with apple credentials.

I have followed all the documentation provided above.

The login on IOS works properly and smooth. The authentication on Android open the browser, make the auth and redirect successfully. But, at the time which my app comes after the redirection with the magic link, the below issue occurs:

AuthException(message: Unable to exchange external code%3A c669fc42a9ff149c7b778865ef977822f.0.mrtst.EItP3ITgGn7irEwox2E0Pw, statusCode: null)
I/flutter (27400): #0      GoTrueClient.getSessionFromUrl (package:gotrue/src/gotrue_client.dart:776:7)
I/flutter (27400): #1      SupabaseAuth._handleDeeplink (package:supabase_flutter/src/supabase_auth.dart:216:43)
I/flutter (27400): #2      SupabaseAuth._handleIncomingLinks.<anonymous closure> (package:supabase_flutter/src/supabase_auth.dart:170:13)
I/flutter (27400): #3      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
I/flutter (27400): #4      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
I/flutter (27400): #5      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:271:7)
I/flutter (27400): #6      _SinkTransformerStreamSubscription._add (dart:async/stream_transformers.dart:63:11)
I/flutter (27400): #7      _EventSinkWrapper.add (dart:async/stream_transformers.dart:13:11)
I/flutter (27400): #8      AppLinksMethodChannel.uriLinkStream.<anonymous closure> (package:app_links/src/app_links_method_channel.dart:56:16)
I/flutter (27400): #9      _HandlerEventSink.add (dart:async/stream_transformers.dart:209:17)
I/flutter (27400): #10     _SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:111:24)
I/flutter (27400): #11     _RootZone.runUnaryGuarde

I have upgraded my Postgres yesterday trying to fix it along with Flutter upgrade and supabase libs with no success.

dshukertjr commented 2 months ago

@formalpair The code query parameter you received does not look like one created by the supabase_flutter library.

Did you happen to follow the instructions on the sign_in_with_apple package for Android? If that is the case, then you need to remove any bit of code related to it as they are probably the cause of the sign-in not working. On our docs we write not to follow any of the instructions on the sign_in_with_apple package.

formalpair commented 2 months ago

@dshukertjr Hey Tyler. My bad. As an attempt I tried to reuse an intent from flutter_facebook_auth which OAuth was properly working, and not realized that was similar procedure that the docs asked to avoid regarding sign_in_with_apple.

My attempt was made in order to get the properly redirection. Removing the intent and all code related to flutter_facebook_auth (I didn't followed the code for Android inside sign_in_with_apple), the Apple page load properly and after insert my credentials, validate the informations and confirm that I want to "continue using Apple sign with my email" the page seems load something on the top bar, but stop, and don't redirect back to my app.

I have made all from the scratch with no success.

It indicates my configs is wrong inside my project?

Im just using the below code as doc asked:

await supabase
            .auth.signInWithOAuth(OAuthProvider.apple,
          redirectTo: 'mydomain://login-callback/'
        );

mydomain://login-callback/ as registered as magic link inside the project.

Thank you.

dshukertjr commented 2 months ago

@formalpair What happens when you call the following currently?

await supabase.auth.signInWithOAuth(OAuthProvider.apple,
  redirectTo: 'mydomain://login-callback/'
);
formalpair commented 2 months ago

@dshukertjr At the moment that the code is called, the browser is opened, returns true and loads successfully the apple login page.

Screen_1 Screen_2
formalpair commented 2 months ago

@dshukertjr Hey Tyler, Any clue from the issue? After put my cloud credentials on last screen above, apple validate them properly but the redirection back to my app didn't occurs

formalpair commented 2 months ago

Hey Guys. Sorry to bother you with it.

I have created a project from scratch using only supabase libs and the issue occurs again:

E/OpenGLRenderer(10495): Unable to match the desired swap behavior.
I/flutter (10495): #0      GoTrueClient.getSessionFromUrl (package:gotrue/src/gotrue_client.dart:776:7)
I/flutter (10495): #1      SupabaseAuth._handleDeeplink (package:supabase_flutter/src/supabase_auth.dart:218:43)
I/flutter (10495): #2      SupabaseAuth._handleIncomingLinks.<anonymous closure> (package:supabase_flutter/src/supabase_auth.dart:170:13)
I/flutter (10495): #8      AppLinksMethodChannel.uriLinkStream.<anonymous closure> (package:app_links/src/app_links_method_channel.dart:56:16)
I/flutter (10495): (elided 26 frames from dart:async)
I/flutter (10495): AuthException(message: Unable to exchange external code%3A c66130c17f1e7477aa792b3ff56af10bb.0.mrtst.2Ar_n8k2eJTDOR1xJjnX9g, statusCode: null)
I/flutter (10495): #0      GoTrueClient.getSessionFromUrl (package:gotrue/src/gotrue_client.dart:776:7)
I/flutter (10495): #1      SupabaseAuth._handleDeeplink (package:supabase_flutter/src/supabase_auth.dart:218:43)
I/flutter (10495): #2      SupabaseAuth._handleIncomingLinks.<anonymous closure> (package:supabase_flutter/src/supabase_auth.dart:170:13)
I/flutter (10495): #8      AppLinksMethodChannel.uriLinkStream.<anonymous closure> (package:app_links/src/app_links_method_channel.dart:56:16)
I/flutter (10495): (elided 26 frames from dart:async)

I'll open a new issue.

formalpair commented 2 months ago

Hello @dshukertjr I have followed again the docs and after few new attempts, it worked properly. Sorry for the confusion and bother you.

Please keep posting videos from Flutter. We really love them. Thanks again for all effort from you and Supabase team. You guys are amazing. It has been a year which Im developing by myself a product, and you and Supabase are part of my learnings, codes and making this to come true. Thank you so much.

To help others like me:

Inside Supabase create the Redirect URL with no "https" and ensure that your domain follow your app domain. Ex: your app is 'com.myapp.app'. Create your URL using 'com.myapp://login-callback/' for example. Don't know the reason, but it worked only following this.