Skip to content

Commit 04615e5

Browse files
committed
fix(app-check, ios): debugToken in config on iOS works now
previously you had to configure it in the simulator environment at startup, now we dynamically stuff it into the running process environment
1 parent df60d83 commit 04615e5

4 files changed

Lines changed: 21 additions & 32 deletions

File tree

docs/app-check/usage/index.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ rnfbProvider.configure({
117117
});
118118
```
119119

120-
Note that the available
121-
122120
### Install the Custom Provider
123121

124122
Once you have the custom provider configured, install it in app-check using the firebase-js-sdk compatible API:
@@ -143,13 +141,7 @@ The [official documentation](https://firebase.google.com/docs/app-check/web/cust
143141

144142
### on iOS
145143

146-
App Check may be used in CI environments by following the upstream documentation to configure a debug token shared with your app in the CI environment.
147-
148-
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.
149-
150-
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.
151-
152-
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.
144+
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.
153145

154146
### on Android
155147

@@ -159,20 +151,20 @@ There are a variety of other ways to obtain and configure debug tokens for AppCh
159151

160152
#### A) When testing on an actual android device (debug build)
161153

162-
1. Start your application on the android device.
163-
2. Use `$adb logcat | grep DebugAppCheckProvider` to grab your temporary secret from the android logs. The output should look lit this:
154+
1. Start your application on the android device.
155+
2. Use `$adb logcat | grep DebugAppCheckProvider` to grab your temporary secret from the android logs. The output should look lit this:
164156

165157
D DebugAppCheckProvider: Enter this debug secret into the allow list in
166158
the Firebase Console for your project: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
167159

168-
3. 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 the debug token you logged in the previous step.
160+
3. 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 the debug token you logged in the previous step.
169161

170162
#### B) Specifying a generated `FIREBASE_APP_CHECK_DEBUG_TOKEN` -- building for CI/CD (debug build)
171163

172164
When you want to test using an Android virtual device -or- when you prefer to (re)use a token of your choice -- e.g. when configuring a CI/CD pipeline -- use the following steps:
173165

174-
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_.
175-
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.:
166+
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_.
167+
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.:
176168

177169
FIREBASE_APP_CHECK_DEBUG_TOKEN="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" react-native run-android
178170

@@ -203,6 +195,6 @@ When using expo-dev-client, the process is a little different, especially on an
203195
}
204196
```
205197

206-
3. Rebuild your development client:
198+
3. Rebuild your development client:
207199

208200
eas build --profile development --platform android

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
"tests:android:emulator:forward": ".github/workflows/scripts/adb_all_emulators.sh 'reverse tcp:8081 tcp:8081'",
4343
"tests:ios:build": "cd tests && yarn detox build --configuration ios.sim.debug",
4444
"tests:ios:build-release": "cd tests && yarn detox build --configuration ios.sim.release",
45-
"tests:ios:test": "cd tests && SIMCTL_CHILD_GULGeneratedClassDisposeDisabled=1 SIMCTL_CHILD_FIRAAppCheckDebugToken=698956B2-187B-49C6-9E25-C3F3530EEBAF yarn detox test --configuration ios.sim.debug --loglevel warn",
46-
"tests:ios:test:debug": "cd tests && SIMCTL_CHILD_GULGeneratedClassDisposeDisabled=1 SIMCTL_CHILD_FIRAAppCheckDebugToken=698956B2-187B-49C6-9E25-C3F3530EEBAF yarn detox test --configuration ios.sim.debug --loglevel warn --inspect",
47-
"tests:ios:test-reuse": "cd tests && SIMCTL_CHILD_GULGeneratedClassDisposeDisabled=1 SIMCTL_CHILD_FIRAAppCheckDebugToken=\"698956B2-187B-49C6-9E25-C3F3530EEBAF\" yarn detox test --configuration ios.sim.debug --reuse --loglevel warn",
48-
"tests:ios:test-cover": "cd tests && SIMCTL_CHILD_GULGeneratedClassDisposeDisabled=1 SIMCTL_CHILD_FIRAAppCheckDebugToken=698956B2-187B-49C6-9E25-C3F3530EEBAF ./node_modules/.bin/nyc yarn detox test --configuration ios.sim.debug --loglevel warn",
49-
"tests:ios:test-cover-reuse": "cd tests && SIMCTL_CHILD_GULGeneratedClassDisposeDisabled=1 SIMCTL_CHILD_FIRAAppCheckDebugToken=698956B2-187B-49C6-9E25-C3F3530EEBAF node_modules/.bin/nyc yarn detox test --configuration ios.sim.debug --reuse --loglevel warn",
45+
"tests:ios:test": "cd tests && SIMCTL_CHILD_GULGeneratedClassDisposeDisabled=1 yarn detox test --configuration ios.sim.debug --loglevel warn",
46+
"tests:ios:test:debug": "cd tests && SIMCTL_CHILD_GULGeneratedClassDisposeDisabled=1 yarn detox test --configuration ios.sim.debug --loglevel warn --inspect",
47+
"tests:ios:test-reuse": "cd tests && SIMCTL_CHILD_GULGeneratedClassDisposeDisabled=1 yarn detox test --configuration ios.sim.debug --reuse --loglevel warn",
48+
"tests:ios:test-cover": "cd tests && SIMCTL_CHILD_GULGeneratedClassDisposeDisabled=1 ./node_modules/.bin/nyc yarn detox test --configuration ios.sim.debug --loglevel warn",
49+
"tests:ios:test-cover-reuse": "cd tests && SIMCTL_CHILD_GULGeneratedClassDisposeDisabled=1 node_modules/.bin/nyc yarn detox test --configuration ios.sim.debug --reuse --loglevel warn",
5050
"tests:ios:pod:install": "cd tests && rm -rf ios/ReactNativeFirebaseDemo.xcworkspace && yarn pod-install",
5151
"format:markdown": "prettier --write \"docs/**/*.md\""
5252
},

packages/app-check/e2e/appcheck.e2e.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe('appCheck()', function () {
2727
},
2828
apple: {
2929
provider: 'debug',
30+
debugToken: '698956B2-187B-49C6-9E25-C3F3530EEBAF',
3031
},
3132
web: {
3233
provider: 'debug',

packages/app-check/ios/RNFBAppCheck/RNFBAppCheckProvider.m

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,14 @@ - (void)configure:(FIRApp *)app
3838

3939
// - determine if debugToken is provided via nullable arg
4040
if ([providerName isEqualToString:@"debug"]) {
41-
// TODO: Currently not handling debugToken argument, relying on existing environment
42-
// variable configuration style.
43-
// - maybe directly setting an environment variable could work?
44-
// https://stackoverflow.com/questions/27139589/whats-the-idiomatic-way-of-setting-an-environment-variable-in-objective-c-coco
45-
// - ...otherwise if env var does not work
46-
// - subclass style: RNFBAppCheckDebugProvider, and we should print local token
47-
// - if a debugToken parameter was supplied, set
48-
// RNFBAppCheckDebugProvider.configuredDebugToken
49-
// - print local token
50-
// https://github.com/firebase/firebase-ios-sdk/blob/c7e95996ff/FirebaseAppCheck/Sources/DebugProvider/FIRAppCheckDebugProviderFactory.m
51-
// - print if current token in provided by configuration, by environment variable, or local
52-
// token?
41+
// The firebase-ios-sdk debug app check provider will take a token from environment if it
42+
// exists:
43+
if (debugToken != nil) {
44+
// We have a debug token, so just need to stuff it in the environment and it will hook up
45+
char *key = "FIRAAppCheckDebugToken", *value = [debugToken UTF8String];
46+
int overwrite = 1;
47+
setenv(key, value, overwrite);
48+
}
5349

5450
self.delegateProvider = [[FIRAppCheckDebugProvider new] initWithApp:app];
5551
}

0 commit comments

Comments
 (0)