Get started using App Check with reCAPTCHA Enterprise in Flutter apps  |  Firebase App Check

Get started using App Check with reCAPTCHA Enterprise in Flutter apps

This page shows you how to set up App Check in a Flutter app, using the reCAPTCHA Enterprise provider. App Check helps to ensure that only your app can access your project's backend resources. To learn more, review our overview of App Check.

App Check requires the use of score-based reCAPTCHA keys, which makes it invisible to users. This means that the reCAPTCHA Enterprise provider won't require users to solve a challenge at any time.

If your use case requires reCAPTCHA Enterprise features not implemented by App Check, or if you want to use App Check with your own custom provider, see Implement a custom App Check provider.

1. Set up your Firebase project

  1. If you haven't already, install and initialize Firebase in your Flutter project.
  2. In the Google Cloud console, go to the Fraud Defense page, and do the following for the reCAPTCHA Enterprise provider:
    1. Make sure that you're in the correct project (see the project picker at the top of the screen).
    2. If prompted, enable the reCAPTCHA Enterprise API.
    3. Create a key based on your target platform:
      • Create an iOS-type key, and specify your app's bundle ID (for example, com.example.my_app).
      • Create an Android-type key, and specify your app's package name (for example, com.example.my_app).
      • Create a Web-type key, and specify each of the domains for your web apps. App Check does not support web apps that serve on more than 250 domains.
    4. Take note of each key. You'll need to add them into the registration flow in the Firebase console.
  3. In the Firebase console, navigate to Security > App Check.
  4. In the Apps tab, register each of your target platform apps to use App Check with the reCAPTCHA Enterprise provider. You'll need to provide the key you got in the Google Cloud console.
  5. Optional: Set the token time to live (TTL).

The default TTL of 1 hour is reasonable for most apps. Note that the App Check library refreshes tokens at approximately half the TTL duration.

  1. Optional: Configure advanced settings.
  2. Click Save.

(Optional) Configure advanced settings

When a user opens your app, reCAPTCHA Enterprise evaluates the level of risk the user interaction under the key poses, and returns a score between 0.0 and 1.0, in increments of 0.1.

For most use cases, the default threshold value of 0.5 is recommended.

2. Add the App Check plugin to your app

To use the reCAPTCHA Enterprise provider, you must add the corresponding App Check plugin.

  1. From the root of your Flutter project, run the following command to install the plugin:
    flutter pub add firebase_app_check
    
  2. Once complete, rebuild your Flutter project:
    flutter run
    

3. Initialize App Check

In your app, you need to initialize App Check before you use any other Firebase services.

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_app_check/firebase_app_check.dart';
import 'firebase_options.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
  await FirebaseAppCheck.instance.activate(
    providerWeb: ReCaptchaEnterpriseProvider(WEB_SITE_KEY),
    providerAndroid: const AndroidReCaptchaProvider(ANDROID_SITE_KEY),
    providerApple: const AppleReCaptchaProvider(IOS_SITE_KEY),
  );
  runApp(App());
}

4. Monitor metrics and enable enforcement

After you've set up App Check in your app, start distributing the updated app to your users.

Monitor metrics

Before you enable enforcement, make sure that doing so won't disrupt your existing legitimate users. You can review App Check metrics for the services you use:

Enable App Check enforcement

Once you're ready to proceed, you can enable App Check enforcement:

Use App Check in debug environments

To run your app in these types of environments after App Check is enforced, you need to create a debug build of your app that uses the App Check debug provider instead of a production attestation provider.

Pricing

App Check creates an assessment on your behalf to validate the user's response token each time your app refreshes its App Check token. Your Firebase project will be charged for each assessment created above the no-cost quota. For details, see reCAPTCHA pricing.

By default, your app will refresh this token twice every 1 hour.