You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/app-check/usage/index.md
+61-14Lines changed: 61 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -54,7 +54,10 @@ This attestation is attached to every request your app makes to your Firebase ba
54
54
This App Check module has built-in support for using the following services as attestation providers:
55
55
56
56
- DeviceCheck on iOS
57
-
- SafetyNet on Android
57
+
- App Attest on iOS
58
+
- Play Integrity on Android
59
+
- SafetyNet on Android (deprecated)
60
+
- Debug providers on both platforms
58
61
59
62
App Check currently works with the following Firebase products:
60
63
@@ -71,26 +74,64 @@ The [official Firebase App Check documentation](https://firebase.google.com/docs
71
74
72
75
Before the App Check package can be used on iOS or Android, the corresponding App must be registered in the firebase console.
73
76
74
-
For instructions on how to generate required keys and register an app for App Check with iOS Device Check and Android SafetyNet, follow **Step 1** in these firebase guides:
77
+
For instructions on how to generate required keys and register an app for the desired attestation provider, follow **Step 1** in these firebase guides:
75
78
76
-
-[Get started using App Check with DeviceCheck on Apple platforms](https://firebase.google.com/docs/app-check/ios/devicecheck-provider?hl=en&authuser=1#project-setup)
77
-
-[Get started using App Check with SafetyNet on Android](https://firebase.google.com/docs/app-check/android/safetynet-provider?hl=en&authuser=1#project-setup)
79
+
-[Get started using App Check with DeviceCheck on Apple platforms](https://firebase.google.com/docs/app-check/ios/devicecheck-provider#project-setup)
80
+
-[Get started using App Check with App Attest on Apple platforms](https://firebase.google.com/docs/app-check/ios/app-attest-provider#project-setup)
81
+
-[Get started using App Check with Play Integrity on Android](https://firebase.google.com/docs/app-check/android/play-integrity-provider#project-setup)
82
+
-[Get started using App Check with SafetyNet on Android (deprecated)](https://firebase.google.com/docs/app-check/android/safetynet-provider#project-setup)
78
83
79
84
> Additionally, You can reference the iOS private key creation and registrations steps outlined in the [Cloud Messaging iOS Setup](/messaging/usage/ios-setup#linking-apns-with-fcm-ios).
80
85
81
-
## Activate
86
+
## Initialize
82
87
83
-
On iOS if you include the App Check 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.
88
+
You must call initialize the AppCheck module prior to calling any firebase back-end services for App Check to function.
84
89
85
-
On Android, App Check 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.
90
+
There are several differences between the web, Apple, and Android platform SDKs produced by Firebase, which react-native-firebase smooths over to give you a common, firebase-js-sdk compatible API.
86
91
87
-
You must call activate prior to calling any firebase back-end services for App Check to function.
92
+
How do we do this? We use the standard firebase-js-sdk v9 API `initializeAppCheck`, and take advantage of its parameters which allow the use of an `AppCheckOptions` argument that itself allows a `CustomProvider`.
93
+
94
+
It is through the use of a react-native-specific `ReactNativeFirebaseAppCheckProvider` that we can offer runtime configuration capability at the javascript level, including the ability to switch providers dynamically.
95
+
96
+
So AppCheck module initialization is done in two steps in react-native-firebase - first you create and configure the custom provider, then you initialize AppCheck using that custom provider.
97
+
98
+
### Configure a Custom Provider
99
+
100
+
To configure the react-native-firebase custom provider, first obtain one, then configure it according to the providers you want to use on each platform.
App Check has an "tokenAutoRefreshEnabled" setting. This may cause App Check to attempt a remote App Check 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.
92
131
93
-
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
132
+
You may configure this setting in `firebase.json` such that your desired configuration is in place even before you the react-native javascript bundle begins executing and allows for runtime configuration.
133
+
134
+
If unset, the "tokenAutoRefreshEnabled" setting will defer to the app's "automatic data collection" setting, which may be set in `firebase.json`, or if you wish directly in the Info.plist or AndroidManifest.xml according to the Firebase native SDK documentation. Unless otherwise configured, it will default to true implying there will be automatic data collection and app check token refresh attempts.
94
135
95
136
## Using App Check tokens for non-firebase services
96
137
@@ -104,9 +145,15 @@ App Check may be used in CI environments by following the upstream documentation
104
145
105
146
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 App Check tokens via setting an environment variable and initializing the debug provider before firebase configure in AppDelegate.m for iOS.
106
147
148
+
This method mainly consists of setting an environment variable in a way that it is visible to the Simulator as it starts up. That environment variable is automatically seen and used by the Firebase Debug provider on iOS.
149
+
150
+
In a future release, the debugToken parameter of the CustomProvider apple options should allow for more dynamic configuration, PRs to the Apple CustomProvider are welcome if you are motivated to implement this feature.
151
+
107
152
### on Android
108
153
109
-
When using a _release_ build, app-check only works when running on actual Android devices. When using a _debug_ build, you have two ways to run your application / tests with App Check support.
154
+
The react-native-firebase CustomProvider implementation allows for runtime configuration of the `debug` provider as well as a `debugToken` in the `android` CustomProvider options. This allows the easy use of a token pre-configured in the Firebase console, allowing for dynamic configuration and testing of AppCheck in CI environments or Android Emulators.
155
+
156
+
There are a variety of other ways to obtain and configure debug tokens for AppCheck testing, a few of which follow:
110
157
111
158
#### A) When testing on an actual android device (debug build)
112
159
@@ -125,16 +172,16 @@ When you want to test using an Android virtual device -or- when you prefer to (r
125
172
1. In the [Project Settings > App Check](https://console.firebase.google.com/project/_/settings/appcheck) section of the Firebase console, choose _Manage debug tokens_ from your app's overflow menu. Then, register a new debug token by clicking the _Add debug token_ button, then _Generate token_.
126
173
2. Pass the token you created in the previous step by supplying a `FIREBASE_APP_CHECK_DEBUG_TOKEN` environment variable to the process that build your react-native android app. e.g.:
Please note that once the android app has successfully passed the app-checks controls on the device, it will keep passing them, whether you rebuild without the secret token or not. To completely reset app-check, you must first uninstall, and then re-build / install.
131
178
132
179
#### C) When using Expo Development Client
133
180
134
181
When using expo-dev-client, the process is a little different, especially on an android emulator.
135
182
136
-
1.In the [Project Settings > App Check](https://console.firebase.google.com/project/_/settings/appcheck) section of the Firebase console, choose _Manage debug tokens_ from your app's overflow menu. Then, register a new debug token by clicking the _Add debug token_ button, then _Generate token_.
137
-
2.Pass the token you created in the previous step by supplying a `FIREBASE_APP_CHECK_DEBUG_TOKEN` environment variable in your eas.json development profile:
183
+
1. In the [Project Settings > App Check](https://console.firebase.google.com/project/_/settings/appcheck) section of the Firebase console, choose _Manage debug tokens_ from your app's overflow menu. Then, register a new debug token by clicking the _Add debug token_ button, then _Generate token_.
184
+
2. Pass the token you created in the previous step by supplying a `FIREBASE_APP_CHECK_DEBUG_TOKEN` environment variable in your eas.json development profile:
138
185
139
186
```json
140
187
{
@@ -156,4 +203,4 @@ When using expo-dev-client, the process is a little different, especially on an
156
203
157
204
3. Rebuild your development client:
158
205
159
-
$ eas build --profile development --platform android
206
+
eas build --profile development --platform android
0 commit comments