Firebase "App Check" is not working in release Android build in React Native

152 views Asked by At

"App Check" is not working in the release build in React Native

I'm following this document: https://rnfirebase.io/app-check/usage

Here is what I've implemented for "App Check".

I have also linked the Firebase project in play integrity.

const firebaseAppCheckFunction = async () => {
    const appCheck = await firebase.appCheck();
    const rnfbProvider = appCheck.newReactNativeFirebaseAppCheckProvider();
    const appCheckTokenFB = await appCheck.getToken();
    console.log('appCheckTokenFB : err ', appCheckTokenFB.token);
    rnfbProvider.configure({
      android: {
        provider: _DEV_ ? 'debug' : 'playIntegrity',
        debugToken: '',
      },
      apple: {
        provider: _DEV_ ? 'debug' : 'appAttestWithDeviceCheckFallback',
        debugToken: '',
      },
    });
    await appCheck.initializeAppCheck({
      provider: rnfbProvider,
      isTokenAutoRefreshEnabled: true,
    });
    try {
      const {token} = await appCheck.getToken(true);
      console.log('tokentokentokentokentoken : ', token);
      if (token.length > 0) {
        Alert.alert('passed');
        // console.log('AppCheck verification passed');
      }
    } catch (error) {
      Alert.alert('failed');
      // console.log('AppCheck verification failed');
    }
  };
1

There are 1 answers

0
Enes Bedirhan Dikmen On

If you have made the required configurations and you can't get the token it might be that current environment you are running the code, simply is not able to pass App Check verification.

It might happen when you run the app using an emulator or when app is not registered to Play Store and not a trusted copy downloaded from it.

To pass this in development process and continue implementing the features as if your app and device is able to receive a token, you need to register a debug token in your Firebase console and use it in your application. Here is details about how you can register a debug token: React Native Firebase Docs

After registering a debug token (which Firebase can auto-generate for you) you need use it in your code like following in the "rnfbProvider" configuration in android.debugToken or ios.debugToken properties:

rnfbProvider.configure({
  android: {
    provider: _DEV_ ? 'debug' : 'playIntegrity',
    debugToken: 'insert_your_debug_token_here',
  },
  apple: {
    provider: _DEV_ ? 'debug' : 'appAttestWithDeviceCheckFallback',
    debugToken: 'insert_your_debug_token_here',
  },
});

After this you will be able to receive a App Check Token even if your current setup is not allowing the check to pass.