Skip to content

Commit a9e7833

Browse files
committed
docs(app-check): add information about new custom provider
1 parent ee7df85 commit a9e7833

2 files changed

Lines changed: 65 additions & 14 deletions

File tree

.spellcheck.dict.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ config-plugin
4444
CP-User
4545
crashlytics
4646
Crashlytics
47+
CustomProvider
4748
datastore
49+
debugToken
4850
DebugView
4951
deprecations
5052
Deprecations
@@ -67,6 +69,7 @@ firebase
6769
Firebase
6870
firebase-admin
6971
firebase-ios-sdk
72+
firebase-js-sdk
7073
FirebaseApp
7174
firestore
7275
Firestore
@@ -129,6 +132,7 @@ performant
129132
personalization
130133
plist
131134
Podfile
135+
pre-configured
132136
pre-fetched
133137
pre-release
134138
pre-rendered

docs/app-check/usage/index.md

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ This attestation is attached to every request your app makes to your Firebase ba
5454
This App Check module has built-in support for using the following services as attestation providers:
5555

5656
- 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
5861

5962
App Check currently works with the following Firebase products:
6063

@@ -71,26 +74,64 @@ The [official Firebase App Check documentation](https://firebase.google.com/docs
7174

7275
Before the App Check package can be used on iOS or Android, the corresponding App must be registered in the firebase console.
7376

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:
7578

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)
7883

7984
> 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).
8085
81-
## Activate
86+
## Initialize
8287

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.
8489

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.
8691

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.
101+
102+
```javascript
103+
rnfbProvider = firebase.appCheck().newReactNativeFirebaseAppCheckProvider();
104+
rnfbProvider.configure({
105+
android: {
106+
provider: 'playIntegrity',
107+
},
108+
apple: {
109+
provider: 'appAttestWithDeviceCheckFallback',
110+
},
111+
web: {
112+
provider: 'reCaptchaV3',
113+
siteKey: 'unknown',
114+
},
115+
});
116+
```
117+
118+
Note that the available
119+
120+
### Install the Custom Provider
121+
122+
Once you have the custom provider configured, install it in app-check using the firebase-js-sdk compatible API:
123+
124+
```javascript
125+
firebase.appCheck().initializeAppCheck({ provider: rnfbProvider, isTokenAutoRefreshEnabled: true });
126+
```
88127

89128
## Automatic Data Collection
90129

91130
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.
92131

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.
94135

95136
## Using App Check tokens for non-firebase services
96137

@@ -104,9 +145,15 @@ App Check may be used in CI environments by following the upstream documentation
104145

105146
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.
106147

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+
107152
### on Android
108153

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:
110157

111158
#### A) When testing on an actual android device (debug build)
112159

@@ -125,16 +172,16 @@ When you want to test using an Android virtual device -or- when you prefer to (r
125172
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_.
126173
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.:
127174

128-
$ FIREBASE_APP_CHECK_DEBUG_TOKEN="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" react-native run-android
175+
FIREBASE_APP_CHECK_DEBUG_TOKEN="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" react-native run-android
129176

130177
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.
131178

132179
#### C) When using Expo Development Client
133180

134181
When using expo-dev-client, the process is a little different, especially on an android emulator.
135182

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:
138185

139186
```json
140187
{
@@ -156,4 +203,4 @@ When using expo-dev-client, the process is a little different, especially on an
156203

157204
3. Rebuild your development client:
158205

159-
$ eas build --profile development --platform android
206+
eas build --profile development --platform android

0 commit comments

Comments
 (0)