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.51k stars 3.92k forks source link

πŸ› [firebase_app_check] Cannot check on Android with PlayIntegrity provider #11117

Closed thorito closed 8 months ago

thorito commented 1 year ago

Bug report

Error returned from API. code: 403 body: App attestation failed.

When initializing AppCheck in Android (release) it always returns an error.

NOTE: The project works with flavors.

Steps to reproduce

Steps to reproduce the behavior:

  1. Initialize Firebase: await Firebase.initializeApp(options: firebaseOptions);
  2. Initialize AppCheck.

NOTE:

  1. In flutter web it works correctly (both in release and in debug).
  2. In Android it only works correctly in Debug mode, but in Release mode, it doesn't :(

const _androidProvider = kReleaseMode
          ? AndroidProvider.playIntegrity
          : AndroidProvider.debug;
const _appleProvider = kReleaseMode
        ? AppleProvider.appAttestWithDeviceCheckFallback
        : AppleProvider.debug;
final _webProvider = isWeb ? reCaptcha : null;

await FirebaseAppCheck.instance.activate(
        androidProvider: _androidProvider,
        appleProvider: _appleProvider,
        webRecaptchaSiteKey: _webProvider,
      );

      FirebaseAppCheck.instance.onTokenChange.listen((token) async {

        await _saveAppCheckToken(
          authRepository: _authRepository,
          token: token,
        );
      });

      try {
        final forceRefresh = _authRepository.getAppCheckToken() == null;
        final tokenAppCheck = await FirebaseAppCheck.instance
            .getToken(forceRefresh);  // <-- Fail

        await _saveAppCheckToken(
          authRepository: _authRepository,
          token: tokenAppCheck,
        );

      } catch (error, stackTrace) {
        logger.d('#AppCheck: ⛔️ ERROR: $error');
     }

Additional context

StackTrace: [firebase_app_check/unknown] com.google.firebase.FirebaseException: Error returned from API. code: 403 body: App attestation failed.

0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652)

1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310)

#2 MethodChannelFirebaseAppCheck.getToken (package:firebase_app_check_platform_interface/src/method_channel/method_channel_firebase_app_check.dart:100) ... ![capture](https://github.com/firebase/flutterfire/assets/594395/52a9f8d7-f9be-469c-8988-ad79f2f4b7a7) ![capture2](https://github.com/firebase/flutterfire/assets/594395/0328cc90-5f1b-43cd-856e-477261b2c777) --- ### Flutter doctor Run `flutter doctor` and paste the output below:
Click To Expand ``` Doctor summary (to see all details, run flutter doctor -v): [βœ“] Flutter (Channel stable, 3.10.4, on macOS 13.4 22F66 darwin-arm64, locale es-ES) [βœ“] Android toolchain - develop for Android devices (Android SDK version 34.0.0) [βœ“] Xcode - develop for iOS and macOS (Xcode 14.3.1) [βœ“] Chrome - develop for the web [βœ“] Android Studio (version 2022.2) [βœ“] VS Code (version 1.79.0) [βœ“] VS Code (version 1.62.3) [βœ“] Connected device (3 available) [βœ“] Network resources β€’ No issues found! ```
--- ### Flutter dependencies Run `flutter pub deps -- --style=compact` and paste the output below:
Click To Expand ``` Dart SDK 3.0.3 Flutter SDK 3.10.4 omni 0.1.0 dependencies: - chat 0.0.1 [flutter common_dependencies common_widgets core avatar_glow avatar_stack bubble emoji_picker_flutter omni_jitsi_meet uuid] - common_dependencies 0.0.1 [flutter auth historical navigator services theme about_custom app_settings audioplayers badges cached_network_image camera circular_reveal_animation device_info_plus device_preview elegant_notification email_validator equatable file_picker firebase_analytics firebase_app_check firebase_auth firebase_core flat flutter_linkify flutter_offline firebase_remote_config flutter_secure_storage flutter_settings_screens flutter_slidable flutter_svg fluttertoast focused_menu_custom freezed_annotation get_it google_fonts hive hive_flutter image_picker infinite_scroll_pagination intl json_annotation launch_review linkify link_preview_generator logger lottie marquee mime package_info_plus open_filex path_provider permission_handler pointer_interceptor provider shared_preferences sentry_flutter stacked shimmer universal_html universal_io url_launcher wakelock] - common_widgets 0.0.1 [flutter common_dependencies core theme] - core 0.0.1 [json_annotation flutter common_dependencies common_widgets notification] - flutter 0.0.0 [characters collection js material_color_utilities meta vector_math sky_engine] - flutter_localizations 0.0.0 [flutter intl characters clock collection js material_color_utilities meta path vector_math] - historical 0.0.1 [flutter common_dependencies] - home 0.0.1 [flutter common_dependencies common_widgets core historical theme login chat] - login 0.0.1 [flutter common_dependencies common_widgets core notification google_sign_in google_sign_in_web] - notification 0.0.1 [flutter common_dependencies common_widgets core firebase_messaging flutter_local_notifications http image] - register 0.0.1 [flutter common_dependencies common_widgets core] - services 0.0.1 [flutter auth core historical dio stomp_dart_client] - splash 0.0.1 [flutter common_dependencies common_widgets core notification] - theme 0.0.1 [flutter common_dependencies] - video 0.0.1 [flutter core chewie video_player_web_hls flutter_cast_framework floating] - webview 0.0.1 [flutter core permission_handler flutter_inappwebview] dev dependencies: - flutter_lints 2.0.1 [lints] - flutter_test 0.0.0 [flutter test_api path fake_async clock stack_trace vector_math async boolean_selector characters collection js matcher material_color_utilities meta source_span stream_channel string_scanner term_glyph] transitive dependencies: - _flutterfire_internals 1.3.2 [collection firebase_core firebase_core_platform_interface flutter meta] - about_custom 2.0.1 [flutter flutter_markdown markdown path simple_mustache url_launcher] - app_settings 4.2.0 [flutter] - archive 3.3.7 [crypto path pointycastle] - args 2.4.2 - async 2.11.0 [collection meta] - audioplayers 3.0.1 [audioplayers_android audioplayers_darwin audioplayers_linux audioplayers_platform_interface audioplayers_web audioplayers_windows flutter http path_provider uuid] - audioplayers_android 2.0.0 [audioplayers_platform_interface flutter] - audioplayers_darwin 3.0.1 [audioplayers_platform_interface flutter] - audioplayers_linux 1.0.4 [audioplayers_platform_interface flutter] - audioplayers_platform_interface 4.0.0 [flutter plugin_platform_interface] - audioplayers_web 2.2.0 [audioplayers_platform_interface flutter flutter_web_plugins js] - audioplayers_windows 1.1.3 [audioplayers_platform_interface flutter] - auth 0.0.1 [flutter common_dependencies core] - auto_route 5.0.4 [flutter path collection meta] - avatar_glow 2.0.2 [flutter] - avatar_stack 1.2.0 [flutter] - badges 3.1.1 [flutter] - boolean_selector 2.1.1 [source_span string_scanner] - bubble 1.2.1 [flutter] - cached_network_image 3.2.3 [flutter flutter_cache_manager octo_image cached_network_image_platform_interface cached_network_image_web] - cached_network_image_platform_interface 2.0.0 [flutter flutter_cache_manager] - cached_network_image_web 1.0.2 [flutter flutter_cache_manager cached_network_image_platform_interface] - camera 0.10.5+2 [camera_android camera_avfoundation camera_platform_interface camera_web flutter flutter_plugin_android_lifecycle quiver] - camera_android 0.10.8+2 [camera_platform_interface flutter flutter_plugin_android_lifecycle stream_transform] - camera_avfoundation 0.9.13+2 [camera_platform_interface flutter stream_transform] - camera_platform_interface 2.5.1 [cross_file flutter plugin_platform_interface stream_transform] - camera_web 0.3.1+4 [camera_platform_interface flutter flutter_web_plugins stream_transform] - characters 1.3.0 - charcode 1.3.1 - chewie 1.3.6 [cupertino_icons collection flutter provider video_player wakelock] - circular_reveal_animation 2.0.1 [flutter] - clock 1.1.1 - collection 1.17.1 - connectivity_plus 2.3.9 [flutter connectivity_plus_platform_interface connectivity_plus_linux connectivity_plus_macos connectivity_plus_web connectivity_plus_windows] - connectivity_plus_linux 1.3.1 [flutter connectivity_plus_platform_interface meta nm] - connectivity_plus_macos 1.2.6 [connectivity_plus_platform_interface flutter] - connectivity_plus_platform_interface 1.2.4 [flutter meta plugin_platform_interface] - connectivity_plus_web 1.2.5 [connectivity_plus_platform_interface flutter_web_plugins flutter js] - connectivity_plus_windows 1.2.2 [connectivity_plus_platform_interface flutter] - convert 3.1.1 [typed_data] - cross_file 0.3.3+4 [js meta] - crypto 3.0.3 [typed_data] - csslib 0.17.3 [source_span] - cupertino_icons 1.0.5 - dbus 0.7.8 [args ffi meta xml] - device_frame 1.1.0 [freezed_annotation flutter] - device_info_plus 8.2.2 [device_info_plus_platform_interface ffi file flutter flutter_web_plugins meta win32] - device_info_plus_platform_interface 7.0.0 [flutter meta plugin_platform_interface] - device_preview 1.1.0 [flutter flutter_localizations provider device_frame freezed_annotation json_annotation shared_preferences collection] - dio 5.2.0+1 [async http_parser meta path] - elegant_notification 1.10.0 [flutter] - email_validator 2.1.17 - emoji_picker_flutter 1.6.1 [flutter flutter_web_plugins plugin_platform_interface shared_preferences] - equatable 2.0.5 [collection meta] - fading_edge_scrollview 3.0.0 [flutter] - fake_async 1.3.1 [clock collection] - ffi 2.0.2 - file 6.1.4 [meta path] - file_picker 5.2.10 [flutter flutter_web_plugins flutter_plugin_android_lifecycle plugin_platform_interface ffi path win32] - firebase_analytics 10.4.2 [firebase_analytics_platform_interface firebase_analytics_web firebase_core firebase_core_platform_interface flutter] - firebase_analytics_platform_interface 3.6.2 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_analytics_web 0.5.4+2 [_flutterfire_internals firebase_analytics_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_app_check 0.1.4+2 [firebase_app_check_platform_interface firebase_app_check_web firebase_core firebase_core_platform_interface flutter] - firebase_app_check_platform_interface 0.0.8+2 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_app_check_web 0.0.10+2 [_flutterfire_internals firebase_app_check_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins js] - firebase_auth 4.6.2 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta] - firebase_auth_platform_interface 6.15.2 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface] - firebase_auth_web 5.5.2 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser js meta] - firebase_core 2.13.1 [firebase_core_platform_interface firebase_core_web flutter meta] - firebase_core_platform_interface 4.8.0 [collection flutter flutter_test meta plugin_platform_interface] - firebase_core_web 2.5.0 [firebase_core_platform_interface flutter flutter_web_plugins js meta] - firebase_messaging 14.6.2 [firebase_core firebase_core_platform_interface firebase_messaging_platform_interface firebase_messaging_web flutter meta] - firebase_messaging_platform_interface 4.5.2 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_messaging_web 3.5.2 [_flutterfire_internals firebase_core firebase_core_web firebase_messaging_platform_interface flutter flutter_web_plugins js meta] - firebase_remote_config 4.2.2 [firebase_core firebase_core_platform_interface firebase_remote_config_platform_interface firebase_remote_config_web flutter] - firebase_remote_config_platform_interface 1.4.2 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface] - firebase_remote_config_web 1.4.2 [firebase_core firebase_core_web firebase_remote_config_platform_interface flutter flutter_web_plugins js] - flat 0.4.1 - floating 1.1.1+1 [flutter] - flutter_blurhash 0.7.0 [flutter] - flutter_cache_manager 3.3.0 [clock collection file flutter http path path_provider pedantic rxdart sqflite uuid] - flutter_cast_framework 0.0.1-alpha.1 [flutter flutter_svg meta] - flutter_inappwebview 6.0.0-beta.23 [flutter flutter_web_plugins js flutter_inappwebview_internal_annotations] - flutter_inappwebview_internal_annotations 1.1.0 - flutter_linkify 6.0.0 [flutter linkify] - flutter_local_notifications 13.0.0 [clock flutter flutter_local_notifications_linux flutter_local_notifications_platform_interface timezone] - flutter_local_notifications_linux 3.0.0+1 [dbus ffi flutter flutter_local_notifications_platform_interface path xdg_directories] - flutter_local_notifications_platform_interface 6.0.0 [flutter plugin_platform_interface] - flutter_markdown 0.6.15 [flutter markdown meta path] - flutter_offline 2.1.0 [flutter connectivity_plus network_info_plus] - flutter_plugin_android_lifecycle 2.0.15 [flutter] - flutter_secure_storage 8.0.0 [flutter flutter_secure_storage_linux flutter_secure_storage_macos flutter_secure_storage_platform_interface flutter_secure_storage_web flutter_secure_storage_windows meta] - flutter_secure_storage_linux 1.1.3 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_macos 3.0.0 [flutter flutter_secure_storage_platform_interface] - flutter_secure_storage_platform_interface 1.0.1 [flutter plugin_platform_interface] - flutter_secure_storage_web 1.1.1 [flutter flutter_secure_storage_platform_interface flutter_web_plugins js] - flutter_secure_storage_windows 2.0.0 [flutter flutter_secure_storage_platform_interface] - flutter_settings_screens 0.3.3-null-safety+2 [flutter path_provider provider shared_preferences pedantic] - flutter_slidable 3.0.0 [flutter] - flutter_svg 2.0.6 [flutter vector_graphics vector_graphics_codec vector_graphics_compiler] - flutter_web_plugins 0.0.0 [flutter js characters collection material_color_utilities meta vector_math] - fluttertoast 8.2.2 [flutter flutter_web_plugins] - focused_menu_custom 1.2.0 [flutter] - freezed_annotation 2.2.0 [collection json_annotation meta] - get_it 7.6.0 [async collection] - google_fonts 4.0.4 [flutter http path_provider crypto] - google_identity_services_web 0.2.1 [js meta] - google_sign_in 6.1.4 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web] - google_sign_in_android 6.1.15 [flutter google_sign_in_platform_interface] - google_sign_in_ios 5.6.2 [flutter google_sign_in_platform_interface] - google_sign_in_platform_interface 2.4.1 [flutter plugin_platform_interface quiver] - google_sign_in_web 0.12.0+2 [flutter flutter_web_plugins google_identity_services_web google_sign_in_platform_interface http js] - hive 2.2.3 [meta crypto] - hive_flutter 1.1.0 [flutter hive path_provider path] - html 0.15.4 [csslib source_span] - http 0.13.6 [async http_parser meta] - http_parser 4.0.2 [collection source_span string_scanner typed_data] - image 3.3.0 [archive meta xml] - image_picker 0.8.7+5 [flutter image_picker_android image_picker_for_web image_picker_ios image_picker_platform_interface] - image_picker_android 0.8.6+20 [flutter flutter_plugin_android_lifecycle image_picker_platform_interface] - image_picker_for_web 2.1.12 [flutter flutter_web_plugins image_picker_platform_interface] - image_picker_ios 0.8.7+4 [flutter image_picker_platform_interface] - image_picker_platform_interface 2.7.0 [cross_file flutter http plugin_platform_interface] - infinite_scroll_pagination 3.2.0 [flutter sliver_tools] - intl 0.18.0 [clock meta path] - js 0.6.7 [meta] - json_annotation 4.8.1 [meta] - launch_review 3.0.1 [flutter] - link_preview_generator 1.2.0 [flutter collection http path universal_html url_launcher] - linkify 5.0.0 - lints 2.1.1 - logger 1.4.0 - logging 1.2.0 - lottie 2.4.0 [archive flutter path vector_math] - markdown 7.1.0 [args meta] - marquee 2.2.3 [fading_edge_scrollview flutter] - matcher 0.12.15 [async meta stack_trace term_glyph test_api] - material_color_utilities 0.2.0 - meta 1.9.1 - mime 1.0.4 - navigator 0.0.1 [flutter auto_route core common_dependencies splash home login register chat video webview] - nested 1.0.0 [flutter] - network_info_plus 2.3.2 [flutter meta network_info_plus_platform_interface network_info_plus_linux network_info_plus_macos network_info_plus_windows network_info_plus_web] - network_info_plus_linux 1.1.2 [collection flutter meta network_info_plus_platform_interface nm] - network_info_plus_macos 1.3.0 [network_info_plus_platform_interface flutter] - network_info_plus_platform_interface 1.1.3 [flutter meta plugin_platform_interface] - network_info_plus_web 1.0.1 [flutter flutter_web_plugins network_info_plus_platform_interface] - network_info_plus_windows 1.0.2 [flutter network_info_plus_platform_interface] - nm 0.5.0 [dbus] - octo_image 1.0.2 [flutter flutter_blurhash] - omni_jitsi_meet 1.0.14 [flutter omni_jitsi_meet_platform_interface omni_jitsi_meet_web_plugin] - omni_jitsi_meet_platform_interface 1.0.14 [flutter plugin_platform_interface] - omni_jitsi_meet_web_plugin 1.0.14 [flutter plugin_platform_interface omni_jitsi_meet_platform_interface flutter_web_plugins js meta] - open_filex 4.3.2 [flutter ffi] - package_info_plus 3.1.2 [ffi flutter flutter_web_plugins http meta path package_info_plus_platform_interface win32] - package_info_plus_platform_interface 2.0.1 [flutter meta plugin_platform_interface] - path 1.8.3 - path_parsing 1.0.1 [vector_math meta] - path_provider 2.0.15 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows] - path_provider_android 2.0.27 [flutter path_provider_platform_interface] - path_provider_foundation 2.2.3 [flutter path_provider_platform_interface] - path_provider_linux 2.1.11 [ffi flutter path path_provider_platform_interface xdg_directories] - path_provider_platform_interface 2.0.6 [flutter platform plugin_platform_interface] - path_provider_windows 2.1.7 [ffi flutter path path_provider_platform_interface win32] - pedantic 1.11.1 - permission_handler 10.3.0 [flutter meta permission_handler_android permission_handler_apple permission_handler_windows permission_handler_platform_interface] - permission_handler_android 10.2.3 [flutter permission_handler_platform_interface] - permission_handler_apple 9.1.0 [flutter permission_handler_platform_interface] - permission_handler_platform_interface 3.10.0 [flutter meta plugin_platform_interface] - permission_handler_windows 0.1.2 [flutter permission_handler_platform_interface] - petitparser 5.4.0 [meta] - platform 3.1.0 - plugin_platform_interface 2.1.4 [meta] - pointer_interceptor 0.9.3+4 [flutter] - pointycastle 3.7.3 [collection convert js] - process 4.2.4 [file path platform] - provider 6.0.5 [collection flutter nested] - quiver 3.2.1 [matcher] - rxdart 0.27.7 - sentry 7.7.0 [http meta stack_trace uuid] - sentry_flutter 7.7.0 [flutter flutter_web_plugins sentry package_info_plus meta] - shared_preferences 2.1.2 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows] - shared_preferences_android 2.1.4 [flutter shared_preferences_platform_interface] - shared_preferences_foundation 2.2.2 [flutter shared_preferences_platform_interface] - shared_preferences_linux 2.2.0 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface] - shared_preferences_platform_interface 2.2.0 [flutter plugin_platform_interface] - shared_preferences_web 2.1.0 [flutter flutter_web_plugins shared_preferences_platform_interface] - shared_preferences_windows 2.2.0 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface] - shimmer 3.0.0 [flutter] - simple_mustache 2.1.0 [logging] - sky_engine 0.0.99 - sliver_tools 0.2.10 [flutter] - source_span 1.9.1 [collection path term_glyph] - sqflite 2.2.8+4 [flutter sqflite_common path] - sqflite_common 2.4.5 [synchronized path meta] - stack_trace 1.11.0 [path] - stacked 3.4.0 [flutter get_it meta provider collection stacked_shared universal_io path] - stacked_shared 1.3.2 [get_it] - stomp_dart_client 0.4.4 [web_socket_channel] - stream_channel 2.1.1 [async] - stream_transform 2.1.0 - string_scanner 1.2.0 [source_span] - synchronized 3.1.0 - term_glyph 1.2.1 - test_api 0.5.1 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph matcher] - timezone 0.9.2 [path] - typed_data 1.3.2 [collection] - universal_html 2.2.3 [async csslib charcode collection html meta source_span typed_data universal_io] - universal_io 2.2.2 [collection meta typed_data] - url_launcher 6.1.11 [flutter url_launcher_android url_launcher_ios url_launcher_linux url_launcher_macos url_launcher_platform_interface url_launcher_web url_launcher_windows] - url_launcher_android 6.0.35 [flutter url_launcher_platform_interface] - url_launcher_ios 6.1.4 [flutter url_launcher_platform_interface] - url_launcher_linux 3.0.5 [flutter url_launcher_platform_interface] - url_launcher_macos 3.0.5 [flutter url_launcher_platform_interface] - url_launcher_platform_interface 2.1.2 [flutter plugin_platform_interface] - url_launcher_web 2.0.17 [flutter flutter_web_plugins url_launcher_platform_interface] - url_launcher_windows 3.0.6 [flutter url_launcher_platform_interface] - uuid 3.0.7 [crypto] - vector_graphics 1.1.6 [flutter vector_graphics_codec] - vector_graphics_codec 1.1.6 - vector_graphics_compiler 1.1.6 [args meta path_parsing xml vector_graphics_codec] - vector_math 2.1.4 - video_player 2.5.0 [flutter html video_player_android video_player_avfoundation video_player_platform_interface video_player_web] - video_player_android 2.4.0 [flutter video_player_platform_interface] - video_player_avfoundation 2.4.0 [flutter video_player_platform_interface] - video_player_platform_interface 6.1.0 [flutter plugin_platform_interface] - video_player_web 2.0.13 [flutter flutter_web_plugins video_player_platform_interface] - video_player_web_hls 1.0.0+1 [flutter flutter_web_plugins http video_player_platform_interface js] - wakelock 0.6.2 [flutter meta wakelock_macos wakelock_platform_interface wakelock_web wakelock_windows] - wakelock_macos 0.4.0 [flutter flutter_web_plugins wakelock_platform_interface] - wakelock_platform_interface 0.3.0 [flutter meta] - wakelock_web 0.4.0 [flutter flutter_web_plugins js wakelock_platform_interface] - wakelock_windows 0.2.1 [flutter wakelock_platform_interface win32] - web_socket_channel 2.4.0 [async crypto stream_channel] - win32 3.1.4 [ffi] - xdg_directories 0.2.0+3 [meta path process] - xml 6.3.0 [collection meta petitparser] ```
---
darshankawar commented 1 year ago

@thorito

[firebase_app_check/unknown] com.google.firebase.FirebaseException: Error returned from API. code: 403 body: App attestation failed.

Since it is throwing app attestation error, For Play Integrity attestation to work, the app must be deployed to Google Play and subsequently downloaded from Google Play.

Can you try the same and see if it helps in your case ?

thorito commented 1 year ago

@thorito

[firebase_app_check/unknown] com.google.firebase.FirebaseException: Error returned from API. code: 403 body: App attestation failed.

Since it is throwing app attestation error, For Play Integrity attestation to work, the app must be deployed to Google Play and subsequently downloaded from Google Play.

Can you try the same and see if it helps in your case ?

I do not have it published on Google Play (it's incomplete)

Anyway, in native android (another project in kotlin), it works correctly for me without having the app published in Google Play

Also, thanks for the information.

darshankawar commented 1 year ago

@thorito Can you check and confirm if the app_id is correct ?

thorito commented 1 year ago

@thorito Can you check and confirm if the app_id is correct ? Hi, It's correct.

capture1 capture2 capture3

Thanks

darshankawar commented 1 year ago

Please check the documentation and regarding enabling enforcement and see if it helps ?

thorito commented 1 year ago

Please check the documentation and regarding enabling enforcement and see if it helps ?

It's the first thing I did. I have followed the documentation, but it doesn't work :(

The application supports: android, ios and web.

devdivr commented 1 year ago

I also faced the same problem. Already checked appId and apiKey but the below error only happens on production. Error returned from API. code: 403 body: App attestation failed

darshankawar commented 1 year ago

I tried with plugin example and ran it in release mode with which I didn't get the reported error.

<img width="381" alt="Screenshot 2023-06-14 at 4 47 44 PM@thorito src="https://github.com/firebase/flutterfire/assets/67046386/606ee26d-e5cc-4c39-bcb1-12e6c7ee03a5">

@thorito Can you try the same plugin example and check if using it, the error persists at your end with your firebase config ?

thorito commented 1 year ago

Hello darshankawar, I have tried the example and it still gives me an error. Steps:

  1. I run flutterfire config --project=my-project --out=lib/firebase_options.dart --android-package-name=my.package.dev --ios-bundle-id=my.package.dev
  2. Changed
    ...
    await FirebaseAppCheck.instance .activate(
     androidProvider: kReleaseMode
       ? AndroidProvider.playIntegrity
       :AndroidProvider.debug,
     appleProvider: kReleaseMode
         ? AppleProvider.appAttestWithDeviceCheckFallback
         :AppleProvider.debug,
     webRecaptchaSiteKey: kWebRecaptchaSiteKey,
    );
    ...
  3. Modify the gradle.build(app) to sign with certificate.
  4. I wrap in a try-catch to see the error when calling the getToken method.
  5. I build the apk with flavors. flutter build apk --flavor predev -t lib/main.dart

info.zip

Thanks

darshankawar commented 1 year ago

Thanks for the update and patience while we try to figure out the root-cause. Using the details provided above, I am able to replicate the reported behavior. Could to be causing due to flavors ?

@thorito If you remove flavor, does the error persist ? Also, can you take a look at this issue and underlying comments to see if they in anyway help further in your case ?

singh3abhi commented 1 year ago

@darshankawar Hey I have an app that is in development (Not on playstore) can I implement an app check in it So that every time the user logins he don't have to do the reCaptcha thing ?

google-oss-bot commented 1 year ago

Hey @thorito. 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!

thorito commented 1 year ago

Hi, I removed the part about flavors but it still returns the same error.

Comments:

  1. I have verified that the 'namespace' and the 'applicationId' are the same as those contained in the 'google-services.json'
  2. Generate the build for web in release and publish to Firebase Hosting with my 'kWebRecaptchaSiteKey' and 'self.FIREBASE_APPCHECK_DEBUG_TOKEN = false;' (index.html) βœ… WORKS !!
  3. I build APK on release. πŸ›‘ ERROR :(
  4. I confirm that the SHA-256 fingerprint appears in the Firebase project configuration when added in appCheck (android).

The app is not published on Google Play. It is a project in flutter on the following platforms: WEB, Android and IOS.

https://github.com/firebase/flutterfire/assets/594395/ac59e209-462e-45aa-af0f-8e22f17fcda0

Below I show the stack of errors that my application returns (it is not the one in the example)

error: [firebase_app_check/unknown] com.google.firebase.FirebaseException: Too many attempts.
  #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652)
  #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310) <asynchronous suspension>
  #2 MethodChannelFirebaseAppCheck.getToken (package:firebase_app_check_platform_interface/src/method_channel/method_channel_firebase_app_check.dart:100)
<asynchronous suspension>
  #3 AppCheck.initAppCheck (package:core/src/app_check.dart:53)
<asynchronous suspension>
  #4 LoginViewModel.checkCredentials (package:login/src/view/view_model/login_view_model.dart:66)
<asynchronous suspension>

Code:

class AppCheck {

  static Future<void> initAppCheck(final String? reCaptcha) async {
    final _analyticsLogger = AppInjector.I.get<AnalyticsLogger>();
    final _authRepository = GetIt.I.get<AuthRepository>();

    final remoteConfigValues = CustomRemoteConfig.instance.remoteConfigValues;
    if (remoteConfigValues.appCheck) {
      final appCheck = FirebaseAppCheck.instance;

      const _androidProvider = kReleaseMode
          ? AndroidProvider.playIntegrity
          : AndroidProvider.debug;
      const _appleProvider = kReleaseMode
        ? AppleProvider.appAttestWithDeviceCheckFallback
        : AppleProvider.debug;
      final _webProvider = reCaptcha;

      logger
        ..d('#AppCheck: AppCheck: πŸš€πŸš€πŸš€')
        ..d('#AppCheck: '
            '1️⃣️: $_androidProvider, '
            '2️⃣: $_appleProvider, '
            '3️⃣: $_webProvider');

      await appCheck.activate(
        androidProvider: _androidProvider,
        appleProvider: _appleProvider,
        webRecaptchaSiteKey: _webProvider,
      );

      appCheck.onTokenChange.listen((token) async {

        _analyticsLogger.logEvent('AppCheck: '
            '${token != null ? 'βœ…' : '❌'}');

        await _saveAppCheckToken(
          authRepository: _authRepository,
          token: token,
        );
      });

      await appCheck.setTokenAutoRefreshEnabled(true);

      try {
        final tokenAppCheck = await appCheck.getToken(true);
        if (tokenAppCheck != null) {
          await _saveAppCheckToken(
            authRepository: _authRepository,
            token: tokenAppCheck,
          );
        }

        _analyticsLogger.logEvent('AppCheck: '
            '${tokenAppCheck != null ? 'βœ…' : '❌'}');

      } catch (error, stackTrace) {
        _analyticsLogger.logEvent('AppCheck: ⛔️ ERROR: $error');
       await Sentry.captureException(error, stackTrace: stackTrace);
      }
    } else {
      _analyticsLogger.logEvent('AppCheck disabled !!');
    }
  }
darshankawar commented 1 year ago

Thanks for the update. I earlier had tried to replicate which gave me reported error. Based on the report and error being received, keeping it open.

sanjaya1996 commented 12 months ago

Hello guys any update on this? I am having same issue with firebase play-integrity API. I am trying with the Debug provider, I enabled app integrity from google play console, I have correct setup in firebase console for play integrity with SHA fingerprint, debug token, etc. I can see the firebase-app-check integrity is enabled from google cloud console as well. But, I am still getting this error when I call getToken() method : com.google.firebase.FirebaseException: Error returned from API. code: 403 body: App attestation failed.

AdamBrejcak commented 11 months ago

Hi guys, same as @sanjaya1996 here, have all setup done, still not working, can't figure out what's wrong, any news on this?

NhaPCS commented 11 months ago

I got same issue

AdamBrejcak commented 11 months ago

I got same issue

Finally, some tokens are verified :) (some are not because users got old version of app), i used same code as in documentation and just setup providers on stores, after some time it started to work

dezsocsete commented 10 months ago

I have setup the SHA-256 keys correctly and for my case it only came down to one thing. Running the app in release mode does not mean anything. It gave me several errors like unknown error, status 403. I have read through the documentation and I have came across a sentence:

"Currently, the built-in Play Integrity provider only supports Android apps distributed by Google Play. To use Play Integrity's off-Play features, or to use App Check with your own custom provider, see Implement a custom App Check provider."

So for it to work you would need to at least deploy the app to Internal Testing.

After that everything worked without issues.

dlewis2017 commented 10 months ago

I'm experiencing similar issues but using Flutter and following these instructions I've deployed the app to internal_testing and downloaded from the app store but I get 401 warnings that result in the call failing. I've also tried the temporary debug token to make calls to my firebase functions from the flutter app in debug mode and that works. My signing cert fingerprint matches (firebase and play store). And both firebase and play store show the app as "registered". Any thoughts?

nishaskinner commented 10 months ago

Could we get confirmation that for "Play Integrity attestation to work, the app must be deployed to Google Play and subsequently downloaded from Google Play"?

If this is the case, does it mean that Firebase App Distribution does not work with Firebase App Check? How does one test this prior to release?

darshankawar commented 10 months ago

/cc @Lyokone

sanjaya1996 commented 9 months ago

Hi any update please, I am using it in React native app and still not able to resolve the issue: com.google.firebase.FirebaseException: Error returned from API. code: 403 body: App attestation failed.

sanjaya1996 commented 9 months ago

Hey @thorito were you able to resolve this issue ? Can you please let us know. Thanks

thorito commented 9 months ago

Hey @thorito were you able to resolve this issue ? Can you please let us know. Thanks

Hello @sanjaya1996 , I have paused it because it still does not work.

Greetings

cashbackdev commented 9 months ago

So for it to work you would need to at least deploy the app to Internal Testing.

didn't work for me..

russellwheatley commented 9 months ago

@thorito - I have just setup Play Integrity for android and I have it working. I only see one SH256 key in the image you provided. I provided the app signing key from the Play Store console and also the SHA256 key for the keystore in the build.gradle, and both are associated with my app in the Firebase console (i.e. pasted into the SHA256 input).

KoheiKanagu commented 9 months ago

Checking for requests to Firebase App Check API and Google Play Integrity API might help identify where the error is occurring. https://console.cloud.google.com/apis/dashboard

flawnn commented 8 months ago

@dlewis2017 Same issue here. Getting a com.google.firebase.FirebaseException: Too many attempts. with Play Integrity.

dehypnosis commented 8 months ago

I want to share my case too for someone. My app was using Google Play App Signing feature which make the app bundle signature on store different from the upload key signature. So, for someone like me, just add GooglePlay App Signing signature to Firebase console app settings. It resolved my issue.

flawnn commented 8 months ago

I want to share my case too for someone. My app was using Google Play App Signing feature which make the app bundle signature on store different from the upload key signature. So, for someone like me, just add GooglePlay App Signing signature to Firebase console app settings. It resolved my issue.

Yeah, this has worked for me now too. But it doesn't resolve the issue that when somebody is testing his app without letting Google to sign it, that it is a massive inconvenience to deal with that. E.g. Debug Tokens cannot be made permanent and would need some human intervention every some time and any other custom solution is just additional work for the end-consume4.

jadam1212 commented 8 months ago

I have setup the SHA-256 keys correctly and for my case it only came down to one thing. Running the app in release mode does not mean anything. It gave me several errors like unknown error, status 403. I have read through the documentation and I have came across a sentence:

"Currently, the built-in Play Integrity provider only supports Android apps distributed by Google Play. To use Play Integrity's off-Play features, or to use App Check with your own custom provider, see Implement a custom App Check provider."

So for it to work you would need to at least deploy the app to Internal Testing.

After that everything worked without issues.

Hi, does this mean that an app that is distributed for testers via Firebase's App Distribution is not gonna work unless I use a custom provider? I have the same issue since I moved to App Distribution (and was working when usedPlay Console's Internal Testing track before..). I have set all the fingerprints for firebase, google cloud console, etc and can't find anything wrong that would explain this problem I am facing..

flawnn commented 8 months ago

I have setup the SHA-256 keys correctly and for my case it only came down to one thing. Running the app in release mode does not mean anything. It gave me several errors like unknown error, status 403. I have read through the documentation and I have came across a sentence: "Currently, the built-in Play Integrity provider only supports Android apps distributed by Google Play. To use Play Integrity's off-Play features, or to use App Check with your own custom provider, see Implement a custom App Check provider." So for it to work you would need to at least deploy the app to Internal Testing. After that everything worked without issues.

Hi, does this mean that an app that is distributed for testers via Firebase's App Distribution is not gonna work unless I use a custom provider? I have the same issue since I moved to App Distribution (and was working when usedPlay Console's Internal Testing track before..). I have set all the fingerprints for firebase, google cloud console, etc and can't find anything wrong that would explain this problem I am facing..

Exactly. Only if installed over Google Play Store (with the Play Store signature), only then will it actually work.

jadam1212 commented 8 months ago

I have setup the SHA-256 keys correctly and for my case it only came down to one thing. Running the app in release mode does not mean anything. It gave me several errors like unknown error, status 403. I have read through the documentation and I have came across a sentence: "Currently, the built-in Play Integrity provider only supports Android apps distributed by Google Play. To use Play Integrity's off-Play features, or to use App Check with your own custom provider, see Implement a custom App Check provider." So for it to work you would need to at least deploy the app to Internal Testing. After that everything worked without issues.

Hi, does this mean that an app that is distributed for testers via Firebase's App Distribution is not gonna work unless I use a custom provider? I have the same issue since I moved to App Distribution (and was working when usedPlay Console's Internal Testing track before..). I have set all the fingerprints for firebase, google cloud console, etc and can't find anything wrong that would explain this problem I am facing..

Exactly. Only if installed over Google Play Store (with the Play Store signature), only then will it actually work.

That is a massive issue then, it kinda renders Firebase App Distribution useless as it re-signs the app bundle..

flawnn commented 8 months ago

I have setup the SHA-256 keys correctly and for my case it only came down to one thing. Running the app in release mode does not mean anything. It gave me several errors like unknown error, status 403. I have read through the documentation and I have came across a sentence: "Currently, the built-in Play Integrity provider only supports Android apps distributed by Google Play. To use Play Integrity's off-Play features, or to use App Check with your own custom provider, see Implement a custom App Check provider." So for it to work you would need to at least deploy the app to Internal Testing. After that everything worked without issues.

Hi, does this mean that an app that is distributed for testers via Firebase's App Distribution is not gonna work unless I use a custom provider? I have the same issue since I moved to App Distribution (and was working when usedPlay Console's Internal Testing track before..). I have set all the fingerprints for firebase, google cloud console, etc and can't find anything wrong that would explain this problem I am facing..

Exactly. Only if installed over Google Play Store (with the Play Store signature), only then will it actually work.

That is a massive issue then, it kinda renders Firebase App Distribution useless as it re-signs the app bundle..

What I did, was just rolling back to SafetyNet for debug builds but yeah, for Firebase App Distribution you need to find a custom way to handle that. I don't really get either why they limited it only on the Play Store with Play Integrity whereas SafetyNet was universally callable.

google-oss-bot commented 8 months ago

Hey @thorito. 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 8 months ago

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

@thorito 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.

gilangliberty commented 7 months ago

I'm facing same issue when i use Firebase App Distribution for internal testing. Any update for this issue?