|
| 1 | +--- |
| 2 | +title: AppCheck |
| 3 | +description: Installation and getting started with AppCheck. |
| 4 | +icon: //static.invertase.io/assets/social/firebase-logo.png |
| 5 | +next: /auth/usage |
| 6 | +previous: /analytics/screen-tracking |
| 7 | +--- |
| 8 | + |
| 9 | +# Installation |
| 10 | + |
| 11 | +This module requires that the `@react-native-firebase/app` module is already setup and installed. To install the "app" |
| 12 | +module, view the [Getting Started](/) documentation. |
| 13 | + |
| 14 | +```bash |
| 15 | +# Install & setup the app module |
| 16 | +yarn add @react-native-firebase/app |
| 17 | + |
| 18 | +# Install the app-check module |
| 19 | +yarn add @react-native-firebase/app-check |
| 20 | + |
| 21 | +# If you're developing your app using iOS, run this command |
| 22 | +cd ios/ && pod install |
| 23 | +``` |
| 24 | + |
| 25 | +AppCheck requires you set the minimum iOS Deployment version in `ios/Podfile` to `11.0` or greater. |
| 26 | + |
| 27 | +# What does it do |
| 28 | + |
| 29 | +App Check works alongside other Firebase services to help protect your backend resources from abuse, such as billing fraud or phishing. With App Check, devices running your app will use an app or device attestation provider that attests to one or both of the following: |
| 30 | + |
| 31 | +- Requests originate from your authentic app |
| 32 | +- Requests originate from an authentic, untampered device |
| 33 | + |
| 34 | +This attestation is attached to every request your app makes to your Firebase backend resources. |
| 35 | + |
| 36 | +<Youtube id="Fjj4fmr2t04" /> |
| 37 | + |
| 38 | +This App Check module has built-in support for using the following services as attestation providers: |
| 39 | + |
| 40 | +- DeviceCheck on iOS |
| 41 | +- SafetyNet on Android |
| 42 | + |
| 43 | +App Check currently works with the following Firebase products: |
| 44 | + |
| 45 | +- Realtime Database |
| 46 | +- Cloud Storage |
| 47 | +- Cloud Functions (callable functions) |
| 48 | + |
| 49 | +The [official Firebase AppCheck documentation](https://firebase.google.com/docs/app-check) has more information, including about the iOS AppAttest provider, and testing/ CI integration, it is worth a read. |
| 50 | + |
| 51 | +# Usage |
| 52 | + |
| 53 | +## Activate |
| 54 | + |
| 55 | +On iOS if you include the AppCheck package, it is activated by default. The only configuration possible is the token auto refresh. When you call activate, the provider (DeviceCheck by default) stays the same but the token auto refresh setting will be changed based on the argument provided. |
| 56 | + |
| 57 | +On Android, AppCheck is not activated until you call the activate method. The provider is not configurable here either but if your app is "debuggable", then the Debug app check provider will be installed, otherwise the SafetyNet provider will be installed. |
| 58 | + |
| 59 | +You must call activate prior to calling any firebase back-end services for AppCheck to function. |
| 60 | + |
| 61 | +## Automatic Data Collection |
| 62 | + |
| 63 | +AppCheck has an "tokenAutoRefreshEnabled" setting. This may cause AppCheck to attempt a remote AppCheck token fetch prior to user consent. In certain scenarios, like those that exist in GDPR-compliant apps running for the first time, this may be unwanted. |
| 64 | + |
| 65 | +If unset, the "tokenAutoRefreshEnabled" setting will defer to the app's "automatic data collection" setting, which may be set in the Info.plist or AndroidManifest.xml |
| 66 | + |
| 67 | +## Using AppCheck tokens for non-firebase services |
| 68 | + |
| 69 | +The [official documentation](https://firebase.google.com/docs/app-check/web/custom-resource) shows how to use `getToken` to access the current AppCheck token and then verify it in external services. |
| 70 | + |
| 71 | +## Testing Environments / CI |
| 72 | + |
| 73 | +AppCheck may be used in CI environments by following the upstream documentation to configure a debug token shared with your app in the CI environment. |
| 74 | + |
| 75 | +In certain react-native testing scenarios it may be difficult to access the shared secret, but the react-native-firebase testing app for e2e testing does successfully fetch AppCheck tokens via: |
| 76 | + |
| 77 | +- including the AppCheck debug test helper in the test app, along with a change to `DetoxTest` for Android |
| 78 | +- by setting an environment variable and initializing the debug provider before firebase configre in `AppDelegate.m` for iOS. |
0 commit comments