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.71k stars 3.97k forks source link

🐛 [firebase_app_check] with AppAttest provider, makes .getToken() fail on iOS #12073

Closed cedvdb closed 10 months ago

cedvdb commented 10 months ago

Bug report

Describe the bug

This is the same issue as this closed issue. However the comment that closed that issue was referring to the debug token, while this issue only arise with the appAttestWithDeviceCheckFallback provider. It works with the debug and device check providers.

When calling await FirebaseAppCheck.instance.getToken() an exception in thrown Unhandled Exception: [firebase_app_check/unknown] The operation couldn’t be completed. (com.firebase.appCheck error 0.) when running on iOS. Every subsequent firebase call to protected firebase services (firestore, firebase storage) fails with permission denied.

Steps to reproduce

Run the sample code below ( add your own firebase options for app initialization).

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  await FirebaseAppCheck.instance.activate(
    appleProvider: AppleProvider.appAttestWithDeviceCheckFallback,
  );
  await FirebaseAppCheck.instance.setTokenAutoRefreshEnabled(true);
  final appCheckToken = await FirebaseAppCheck.instance.getToken();
  print(appCheckToken);
  runApp(
    const MaterialApp(
      title: 'test',
      home: LoadingIndicator(),
    ),
  );
}

Flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.4, on macOS 14.2.1 23C71 darwin-arm64, locale en-BE)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] VS Code (version 1.85.1)
[✓] Connected device (4 available)
[✓] Network resources

Flutter dependencies

0.application git:(dev) ✗ flutter pub deps -- --style=compact | grep firebase
- infrastructure 0.0.1 [flutter flutter_test flutter_localizations logger firebase_remote_config firebase_core firebase_auth firebase_analytics firebase_crashlytics firebase_storage firebase_app_check cloud_firestore fake_cloud_firestore firebase_auth_mocks flutter_spinkit smooth_page_indicator flutter_svg intl equatable rxdart uuid meta collection universal_platform stringr pointer_interceptor mocktail hive_flutter dio dio_smart_retry http_parser url_launcher share_plus package_info_plus geoflutterfire_plus add_2_calendar animated_list_plus]
- _flutterfire_internals 1.3.12 [collection firebase_core firebase_core_platform_interface flutter meta]
- cloud_firestore 4.13.1 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- cloud_firestore_platform_interface 6.0.5 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 3.8.5 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins js]
- fake_cloud_firestore 2.4.3 [flutter cloud_firestore cloud_firestore_platform_interface collection plugin_platform_interface quiver rxdart mock_exceptions fake_firebase_security_rules rx equatable]
- fake_firebase_security_rules 0.5.3 [antlr4 cel equatable logger tuple]
- firebase_analytics 10.7.0 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter]
- firebase_analytics_platform_interface 3.8.0 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_analytics_web 0.5.5+7 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- firebase_app_check 0.2.1+4 [firebase_app_check_platform_interface firebase_app_check_web firebase_core firebase_core_platform_interface flutter]
- firebase_app_check_platform_interface 0.1.0+6 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_app_check_web 0.1.0+6 [_flutterfire_internals firebase_app_check_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js]
- firebase_auth 4.14.0 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_auth_mocks 0.13.0 [flutter firebase_auth firebase_core meta equatable dart_jsonwebtoken uuid firebase_auth_platform_interface mock_exceptions]
- firebase_auth_platform_interface 7.0.4 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 5.8.7 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser js meta]
- firebase_core 2.22.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_core_platform_interface 5.0.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.8.1 [firebase_core_platform_interface flutter flutter_web_plugins js meta]
- firebase_crashlytics 3.4.4 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace]
- firebase_crashlytics_platform_interface 3.6.12 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_remote_config 4.3.4 [firebase_core firebase_core_platform_interface firebase_remote_config_platform_interface firebase_remote_config_web flutter]
- firebase_remote_config_platform_interface 1.4.12 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_remote_config_web 1.4.12 [firebase_core firebase_core_web firebase_remote_config_platform_interface flutter flutter_web_plugins js]
- firebase_storage 11.5.1 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter]
- firebase_storage_platform_interface 5.0.2 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_storage_web 3.6.13 [_flutterfire_internals async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http js meta]
danagbemava-nc commented 10 months ago

Hi @cedvdb, is this happening on specific iOS devices/versions or is it happening on all the devices you have tested? Can you also check the following issues to see if they are similar to your case?

https://github.com/firebase/flutterfire/issues/11629 https://github.com/firebase/flutterfire/issues/10683

cedvdb commented 10 months ago

@danagbemava-nc The first issue does not have a reproduction example. The second one is marked as blocked by the SDK but is no longer blocked. Both of those issue look like the same as mine. Please update the label on the second one though as it might mislead further investigation.

danagbemava-nc commented 10 months ago

Thanks for the update. Deduplicating this into the existing issues