firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.72k stars 3.97k forks source link

[firebase_auth/unknown] null #9910

Closed rehusevych closed 1 year ago

rehusevych commented 2 years ago

Bug report When I tried to login in app using firebase_auth with keycloak and after calling signInWithCredential() the following exception is thrown: [firebase_auth/unknown] null

This exception thrown only on Android(on iOS everything works fine) and in debug console there is no explanation of this error.

Additional context I using firebase_auth: ^4.0.1


Flutter doctor

Run `flutter doctor` and paste the output below:

PS  flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.3.6, on Microsoft Windows [Version 10.0.19044.1706], locale uk-UA)
Checking Android licenses is taking an unexpectedly long time...[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0-rc4)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.3.6)
[√] Android Studio (version 2021.3)
[√] Connected device (3 available)
[√] HTTP Host Availability        

• No issues found!

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Dart SDK 2.18.2
Flutter SDK 3.3.6
influencers 1.0.0+1

dependencies:
- align_positioned 3.0.0 [matrix4_transform flutter]
- app_settings 4.1.8 [flutter]
- auto_route 5.0.1 [flutter path collection meta]
- auto_size_text 3.0.0 [flutter]
- cached_network_image 3.2.1 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web]
- cloud_firestore 4.0.1 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- collection 1.16.0
- confetti 0.7.0 [flutter vector_math]
- connectivity_plus 1.4.0 [flutter meta connectivity_plus_platform_interface connectivity_plus_linux connectivity_plus_macos connectivity_plus_web 
connectivity_plus_windows]
- country_picker 2.0.16 [flutter collection]
- cupertino_icons 1.0.5
- dartx 1.1.0 [characters collection crypto meta path time]
- date_utils 0.2.0 [intl]
- dio 4.0.6 [http_parser path]
- dotted_line 3.1.0 [flutter]
- file_picker 4.6.1 [flutter flutter_web_plugins flutter_plugin_android_lifecycle plugin_platform_interface ffi path win32]
- firebase_auth 4.0.1 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_core 2.0.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_crashlytics 3.0.1 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace]
- firebase_messaging 14.0.1 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta]
- flowder 0.2.0 [flutter flutter_web_plugins dio]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_bloc 8.1.1 [flutter bloc provider]
- flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid]
- flutter_calendar_carousel 2.4.0 [intl flutter]
- flutter_facebook_auth 4.4.1+1 [flutter flutter_facebook_auth_platform_interface flutter_facebook_auth_web]
- flutter_local_notifications 9.9.1 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone]      
- flutter_localizations 0.0.0 [flutter intl characters clock collection material_color_utilities meta path vector_math]
- flutter_mailer 2.0.1 [flutter]
- flutter_neat_and_clean_calendar 0.3.9+23 [flutter intl macos_ui]
- flutter_secure_storage 5.1.2 [flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows meta]
- flutter_spinkit 5.1.0 [flutter]
- flutter_staggered_grid_view 0.6.2 [flutter]
- flutter_svg 1.1.5 [flutter meta path_drawing vector_math xml]
- fpdart 0.2.0
- freezed 2.1.0+1 [analyzer build build_config collection meta source_gen freezed_annotation json_annotation]
- google_sign_in 5.4.2 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web]
- hive_flutter 1.1.0 [flutter hive path_provider path]
- image_gallery_saver 1.7.1 [flutter]
- image_picker 0.8.6 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_platform_interface]
- intl 0.17.0 [clock path]
- json_annotation 4.7.0 [meta]
- keyboard_actions 4.1.0 [flutter]
- liquid_progress_indicator 0.4.0 [flutter]
- logger 1.1.0
- mime 1.0.2
- modal_bottom_sheet 2.1.2 [flutter]
- open_file 3.2.1 [flutter ffi]
- openid_client 0.4.6 [jose pointycastle http logging args meta clock]
- package_info_plus 1.4.2 [flutter package_info_plus_platform_interface package_info_plus_linux package_info_plus_macos package_info_plus_windows package_info_plus_web]
- path_provider 2.0.11 [flutter path_provider_android path_provider_ios path_provider_linux path_provider_macos path_provider_platform_interface path_provider_windows]
- percent_indicator 4.2.2 [flutter]
- permission_handler 10.1.0 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface]
- photo_view 0.13.0 [flutter]
- pretty_dio_logger 1.2.0-beta-1 [dio]
- provider 6.0.3 [collection flutter nested]
- retrofit 3.3.1 [dio meta]
- rxdart 0.27.5
- share_plus 4.5.3 [cross_file meta mime flutter share_plus_platform_interface share_plus_linux share_plus_macos share_plus_windows share_plus_web]- shared_preferences 2.0.15 [flutter shared_preferences_android shared_preferences_ios shared_preferences_linux shared_preferences_macos shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- shimmer 2.0.0 [flutter]
- syncfusion_flutter_calendar 20.3.47 [flutter timezone syncfusion_flutter_core syncfusion_flutter_datepicker intl]
- table_calendar 3.0.7 [flutter intl simple_gesture_detector]
- url_launcher 6.1.6 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows]
- video_player 2.4.7 [flutter html video_player_android video_player_avfoundation video_player_platform_interface video_player_web]
darshankawar commented 2 years ago

login in app using firebase_auth with keycloak

@rehusevych If you simply using only firebase_auth stand-alone without third party and try the steps you mentioned in description, does it still give you the reported error or not ?

rehusevych commented 2 years ago

login in app using firebase_auth with keycloak

@rehusevych If you simply using only firebase_auth stand-alone without third party and try the steps you mentioned in description, does it still give you the reported error or not ?

I create new project without third party packages and firebase_auth with the same firebase project start working fine without any errors. Maybe you have any ideas what could be the reason why firebase_auth doesn't work only on android with third party packages?

darshankawar commented 2 years ago

Good to know that without third party packages, there's no issue. Looking at your pubspec.yaml, I see lot of external plugins you are using and there could be a conflict between one of them with firebase_auth which you'll probably need to find out, because with the error, it is tough to tell what exactly could be causing it.

It could also be that, you are probably trying to use firebase core before the FirebaseApp initialization, so make sure you are initializing the FirebaseApp first and properly before using any of other services.

I will go ahead and close the issue for now, as it is not related to firebase_auth, but could be due to external dependency conflict or the way you are initializing the app for which you can take a look at documentation and confirm. If you disagree or are able to replicate this error only using firebase_auth consistently, write in comments and I'll reopen it.

beleven-devs commented 2 years ago

Good to know that without third party packages, there's no issue. Looking at your pubspec.yaml, I see lot of external plugins you are using and there could be a conflict between one of them with firebase_auth which you'll probably need to find out, because with the error, it is tough to tell what exactly could be causing it.

It could also be that, you are probably trying to use firebase core before the FirebaseApp initialization, so make sure you are initializing the FirebaseApp first and properly before using any of other services.

I will go ahead and close the issue for now, as it is not related to firebase_auth, but could be due to external dependency conflict or the way you are initializing the app for which you can take a look at documentation and confirm. If you disagree or are able to replicate this error only using firebase_auth consistently, write in comments and I'll reopen it.

Hi again, today I tried to change signInWithCredentialto signInWIthEmailAndPassword and in this way everything works good on Android with all third party packages. signInWithCredential works correctly on iOS, but on Android thrown this exception [firebase_auth/unknown] null. Now I'm sure, that problem isn't due to use third-party packages and not due to FirebaseApp initialization before using firebase_core

yura2000 commented 2 years ago

Hi @darshankawar, having same issue

darshankawar commented 2 years ago

@rehusevych @yura2000 Would be great if you could provide us a minimal reproducible code sample that shows the reported error, so that it'll help us to make this issue actionable.

rehusevych commented 2 years ago

@rehusevych @yura2000 Would be great if you could provide us a minimal reproducible code sample that shows the reported error, so that it'll help us to make this issue actionable. yeah, of course, here is a code sample:


TaskEither<AuthFailure, AuthUserData> signInWithSSO({
required void Function(bool) onLaunched,
}) {
urlLauncher(String url) async {
if (await canLaunchUrlString(url)) {
await launchUrlString(url);
} else {
throw 'Could not launch $url';
}
}
return TaskEither.tryCatch(
  () async {
    final uri = Uri.parse(keycloakUrl);
    final scopes = List<String>.of([
      'profile',
      'openid',
      'offline_access',
    ]);
    const port = 4200;

    final issuer = await Issuer.discover(uri);
    final client = Client(issuer, keycloakClientId);

    final authenticator = Authenticator(
      client,
      scopes: scopes,
      port: port,
      urlLancher: urlLauncher,
    );

    final auth = await authenticator.authorize();
    unawaited(closeInAppWebView());
    final token = await auth.getTokenResponse();
    final info = await auth.getUserInfo();
    if (token.accessToken != null) {
      try {
        final provider = OAuthProvider(oAuthKeycloak).credential(
          idToken: token.idToken.toCompactSerialization(),
        );
        await FirebaseAuth.instance.signInWithCredential(provider);
      } catch (e) {
        //here exception thrown
        throw Exception(e);
      }
      await _store.persistAccessToken(token.accessToken!);
    }
    if (token.refreshToken != null) {
      await _store.persistRefreshToken(token.refreshToken!);
    }

    return AuthUserData(
      token: token,
      email: info.email,
      given_name: info.givenName,
      family_name: info.familyName,
    );
  },
  AuthFailure.ssoUnavailable,
);

}

darshankawar commented 2 years ago

@rehusevych Sorry but above code is not complete and we can't use it directly as it seems to contain custom implementation, that' why we requested earlier to provide a minimal reproducible code sample without third party plugins that we can directly use to verify this issue further.

rehusevych commented 1 year ago

@rehusevych Sorry but above code is not complete and we can't use it directly as it seems to contain custom implementation, that' why we requested earlier to provide a minimal reproducible code sample without third party plugins that we can directly use to verify this issue further. Sorry for a long response, I created a new public repository with minimal reproducible code sample. Here is a link to repository: repository link

darshankawar commented 1 year ago

Looking at the repo code you provided above, you seem to be providing a custom OAuthProvider in keycloak which I am not sure could be leading to the behavior you are seeing. Also, I see other custom (third party) implementations using openid, so it could be a combination of that. Can you try same scenario using any other third party library such as https://github.com/amrfarid140/firebase_auth_oauth and see if using it, you still get same error or not ? Also, I would still like a narrowed down example with only using firebase_auth and url_launcher and see if it still triggers same error or not. You may also try to run in verbose mode and see if you get any additional logs in the console for the error.

rehusevych commented 1 year ago

Looking at the repo code you provided above, you seem to be providing a custom OAuthProvider in keycloak which I am not sure could be leading to the behavior you are seeing. Also, I see other custom (third party) implementations using openid, so it could be a combination of that. Can you try same scenario using any other third party library such as https://github.com/amrfarid140/firebase_auth_oauth and see if using it, you still get same error or not ? Also, I would still like a narrowed down example with only using firebase_auth and url_launcher and see if it still triggers same error or not. You may also try to run in verbose mode and see if you get any additional logs in the console for the error.

Hi, I'm tried to use firebase_auth_oauth package, but but it does not support auth through keycloak, so I'm tried to use https://pub.dev/packages/openidconnect but still getting the same error. Verbose logs do not write anything

darshankawar commented 1 year ago

I am not sure about usage, integration and support of keycloak with firebase_auth and that seems to be the reason of the error and since it is third party, I suggest you to reach out to dedicated plugin repo. Closing for now, as this doesn't seem to be firebase_auth plugin issue. If you disagree, write in comments and I'll reopen it.

rehusevych commented 1 year ago

I am not sure about usage, integration and support of keycloak with firebase_auth and that seems to be the reason of the error and since it is third party, I suggest you to reach out to dedicated plugin repo. Closing for now, as this doesn't seem to be firebase_auth plugin issue. If you disagree, write in comments and I'll reopen it.

Sorry, but if keycloak is not supported by firebase_auth, why on iOS everything works good? You have any idea about this?

rehusevych commented 1 year ago

I am not sure about usage, integration and support of keycloak with firebase_auth and that seems to be the reason of the error and since it is third party, I suggest you to reach out to dedicated plugin repo. Closing for now, as this doesn't seem to be firebase_auth plugin issue. If you disagree, write in comments and I'll reopen it.

Hi, sorry for stealing your time, but I really need a solution to this problem. I've tried a lot of things, but I still can't find a solution

darshankawar commented 1 year ago

Reopening and for team's insights on this use case.

/cc @Lyokone

yura2000 commented 1 year ago

@darshankawar, @Lyokone any updates?

yura2000 commented 1 year ago

@darshankawar, @Lyokone Still an issue! Can't go live to the stores. Please, help!

russellwheatley commented 1 year ago

There are no updates. We need a reproducible sample, ideally a GitHub repo where I only have to setup my own Firebase project on the app. Please also include any additional configurations steps that might be necessary for third party setup. This is the quickest way to get our attention and a fix for the issue. Thanks.

google-oss-bot commented 1 year ago

Hey @rehusevych. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

google-oss-bot commented 1 year ago

Since there haven't been any recent updates here, I am going to close this issue.

@rehusevych if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.