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
703 stars 167 forks source link

Error on Apple OAuth Login on Flutter/Android (Unable to exchange external code) #892

Closed formalpair closed 5 months ago

formalpair commented 5 months ago

Describe the bug Below error occur when try to login using Apple OAuth in Android with Flutter.

SupabaseAuthState handleDeeplink com.formalpair://login-callback/?error=server_error&error_code=500&error_description=Unable+to+exchange+external+code%3A+cb8dc01f2a6414e479c11eb44da2d5220.0.mrtst.Q-QzxS4mMFoe-Aa37MUrCA#error=server_error&error_code=500&error_description=Unable+to+exchange+external+code%253A+cb8dc01f2a6414e479c11eb44da2d5220.0.mrtst.Q-QzxS4mMFoe-Aa37MUrCA

To Reproduce Steps to reproduce the behavior:

  1. Create a new Flutter Project on Android Studio.
  2. Add supabase dependencies (supabase_flutter: ^2.5.1 supabase: ^2.1.1)
  3. Initialize supabase inside main
  4. Add a new intent to get the browser redirection
  5. Create an Elevated Button calling the follow method

bool loginResponse = await supabase.auth.signInWithOAuth(OAuthProvider.apple, redirectTo: 'domain://login-callback/' );

  1. Create a redirect url 'domain://login-callback/' inside Supabase
  2. Insert valid credentials on browser
  3. Accept and continue
  4. See error on Android Studio terminal

Expected behavior User properly authenticated on supabase with apple credentials

Screenshots

1 2 3

Version (please complete the following information): On Linux/macOS

user@MacBook-Air teste_apple_login % dart pub deps
Dart SDK 3.3.4 Flutter SDK 3.19.6 teste_apple_login 1.0.0+1 ├── cupertino_icons 1.0.8 ├── flutter 0.0.0 │ ├── characters 1.3.0 │ ├── collection 1.18.0 │ ├── material_color_utilities 0.8.0 │ │ └── collection... │ ├── meta 1.11.0 │ ├── sky_engine 0.0.99 │ └── vector_math 2.1.4 ├── flutter_lints 3.0.2 │ └── lints 3.0.0 ├── flutter_test 0.0.0 │ ├── boolean_selector 2.1.1 │ │ ├── source_span... │ │ └── string_scanner... │ ├── clock 1.1.1 │ ├── fake_async 1.3.1 │ │ ├── clock... │ │ └── collection... │ ├── leak_tracker 10.0.0 │ │ ├── clock... │ │ ├── collection... │ │ ├── meta... │ │ ├── path... │ │ └── vm_service... │ ├── leak_tracker_flutter_testing 2.0.1 │ │ ├── flutter... │ │ ├── leak_tracker... │ │ ├── leak_tracker_testing... │ │ ├── matcher... │ │ └── meta... │ ├── leak_tracker_testing 2.0.1 │ │ ├── leak_tracker... │ │ ├── matcher... │ │ └── meta... │ ├── matcher 0.12.16+1 │ │ ├── async... │ │ ├── meta... │ │ ├── stack_trace... │ │ ├── term_glyph... │ │ └── test_api... │ ├── path 1.9.0 │ ├── source_span 1.10.0 │ │ ├── collection... │ │ ├── path... │ │ └── term_glyph... │ ├── stack_trace 1.11.1 │ │ └── path... │ ├── stream_channel 2.1.2 │ │ └── async... │ ├── string_scanner 1.2.0 │ │ └── source_span... │ ├── term_glyph 1.2.1 │ ├── test_api 0.6.1 │ │ ├── async... │ │ ├── boolean_selector... │ │ ├── collection... │ │ ├── meta... │ │ ├── source_span... │ │ ├── stack_trace... │ │ ├── stream_channel... │ │ ├── string_scanner... │ │ └── term_glyph... │ ├── vm_service 13.0.0 │ ├── async... │ ├── characters... │ ├── collection... │ ├── flutter... │ ├── material_color_utilities... │ ├── meta... │ └── vector_math... ├── supabase 2.1.1 │ ├── functions_client 2.0.0 │ │ ├── http... │ │ └── yet_another_json_isolate... │ ├── gotrue 2.6.0 │ │ ├── jwt_decode 0.3.1 │ │ ├── retry 3.1.2 │ │ ├── collection... │ │ ├── crypto... │ │ ├── http... │ │ ├── meta... │ │ └── rxdart... │ ├── postgrest 2.1.1 │ │ ├── http... │ │ ├── meta... │ │ └── yet_another_json_isolate... │ ├── realtime_client 2.0.4 │ │ ├── web_socket_channel 2.4.5 │ │ │ ├── async... │ │ │ ├── crypto... │ │ │ ├── stream_channel... │ │ │ └── web... │ │ ├── collection... │ │ ├── http... │ │ └── meta... │ ├── rxdart 0.27.7 │ ├── storage_client 2.0.1 │ │ ├── mime 1.0.5 │ │ ├── http... │ │ ├── http_parser... │ │ ├── meta... │ │ └── retry... │ ├── yet_another_json_isolate 2.0.0 │ │ └── async... │ └── http... └── supabase_flutter 2.5.1 ├── app_links 4.0.1 │ ├── flutter_web_plugins 0.0.0 │ │ ├── characters... │ │ ├── collection... │ │ ├── flutter... │ │ ├── material_color_utilities... │ │ ├── meta... │ │ └── vector_math... │ ├── gtk 2.1.0 │ │ ├── ffi 2.1.2 │ │ ├── flutter... │ │ └── meta... │ ├── plugin_platform_interface 2.1.8 │ │ └── meta... │ ├── web 0.5.1 │ └── flutter... ├── async 2.11.0 │ ├── collection... │ └── meta... ├── crypto 3.0.3 │ └── typed_data 1.3.2 │ └── collection... ├── http 1.2.1 │ ├── http_parser 4.0.2 │ │ ├── collection... │ │ ├── source_span... │ │ ├── string_scanner... │ │ └── typed_data... │ ├── async... │ ├── meta... │ └── web... ├── path_provider 2.1.3 │ ├── path_provider_android 2.2.4 │ │ ├── flutter... │ │ └── path_provider_platform_interface... │ ├── path_provider_foundation 2.3.2 │ │ ├── flutter... │ │ └── path_provider_platform_interface... │ ├── path_provider_linux 2.2.1 │ │ ├── xdg_directories 1.0.4 │ │ │ ├── meta... │ │ │ └── path... │ │ ├── ffi... │ │ ├── flutter... │ │ ├── path... │ │ └── path_provider_platform_interface... │ ├── path_provider_platform_interface 2.1.2 │ │ ├── platform 3.1.4 │ │ ├── flutter... │ │ └── plugin_platform_interface... │ ├── path_provider_windows 2.2.1 │ │ ├── win32 5.4.0 │ │ │ └── ffi... │ │ ├── ffi... │ │ ├── flutter... │ │ ├── path... │ │ └── path_provider_platform_interface... │ └── flutter... ├── shared_preferences 2.2.3 │ ├── shared_preferences_android 2.2.2 │ │ ├── flutter... │ │ └── shared_preferences_platform_interface... │ ├── shared_preferences_foundation 2.3.5 │ │ ├── flutter... │ │ └── shared_preferences_platform_interface... │ ├── shared_preferences_linux 2.3.2 │ │ ├── file 7.0.0 │ │ │ ├── meta... │ │ │ └── path... │ │ ├── flutter... │ │ ├── path... │ │ ├── path_provider_linux... │ │ ├── path_provider_platform_interface... │ │ └── shared_preferences_platform_interface... │ ├── shared_preferences_platform_interface 2.3.2 │ │ ├── flutter... │ │ └── plugin_platform_interface... │ ├── shared_preferences_web 2.3.0 │ │ ├── flutter... │ │ ├── flutter_web_plugins... │ │ ├── shared_preferences_platform_interface... │ │ └── web... │ ├── shared_preferences_windows 2.3.2 │ │ ├── file... │ │ ├── flutter... │ │ ├── path... │ │ ├── path_provider_platform_interface... │ │ ├── path_provider_windows... │ │ └── shared_preferences_platform_interface... │ └── flutter... ├── url_launcher 6.2.6 │ ├── url_launcher_android 6.3.1 │ │ ├── flutter... │ │ └── url_launcher_platform_interface... │ ├── url_launcher_ios 6.2.5 │ │ ├── flutter... │ │ └── url_launcher_platform_interface... │ ├── url_launcher_linux 3.1.1 │ │ ├── flutter... │ │ └── url_launcher_platform_interface... │ ├── url_launcher_macos 3.1.0 │ │ ├── flutter... │ │ └── url_launcher_platform_interface... │ ├── url_launcher_platform_interface 2.3.2 │ │ ├── flutter... │ │ └── plugin_platform_interface... │ ├── url_launcher_web 2.3.1 │ │ ├── flutter... │ │ ├── flutter_web_plugins... │ │ ├── url_launcher_platform_interface... │ │ └── web... │ ├── url_launcher_windows 3.1.1 │ │ ├── flutter... │ │ └── url_launcher_platform_interface... │ └── flutter... ├── flutter... ├── meta... └── supabase...

Additional context Maybe it can be related to my server. I have already upgraded Postgres's to last available version.

dshukertjr commented 5 months ago

Please try to start a fresh Flutter project and carefully follow the instructions described here again.

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

formalpair commented 5 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.