Skip to content

feat(app-check): add AppCheck implementation #5581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions .github/workflows/create_test_patches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ jobs:
mkdir patches || true
for PACKAGE in $PACKAGE_LIST; do
echo "Installing package $PACKAGE into fresh template app, then clobbering with PR version"
yarn add @react-native-firebase/$PACKAGE
pushd node_modules/@react-native-firebase
tar -zxf $HOME/packages/react-native-firebase-${PACKAGE}-v*
mv $PACKAGE/package.json package/
\rm -fr $PACKAGE
mv package $PACKAGE
popd
npx patch-package @react-native-firebase/$PACKAGE || true
yarn add @react-native-firebase/$PACKAGE || true
if [ -d node_modules/@react-native-firebase/$PACKAGE ]; then
pushd node_modules/@react-native-firebase
tar -zxf $HOME/packages/react-native-firebase-${PACKAGE}-v*
mv $PACKAGE/package.json package/
\rm -fr $PACKAGE
mv package $PACKAGE
popd
npx patch-package @react-native-firebase/$PACKAGE || true
fi
done
ls -la $HOME/template/patches
shell: bash
Expand All @@ -95,9 +97,9 @@ jobs:
with:
name: patches
path: ~/template/patches/

# create a comment on the PR and any related issues with a direct link to the archive,
# a call for testers, and perhaps a paste-able set of commands to install them
# a call for testers, and perhaps a paste-able set of commands to install them
# (mkdir patches, curl -o etc, npx patch-package)
# You need an artifact id to get a download link for it.
# You need a workflow run id to get an artifact id.
Expand Down
8 changes: 3 additions & 5 deletions .github/workflows/tests_e2e_ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ jobs:
- name: Pod Install
uses: nick-invision/retry@v2
with:
timeout_minutes: 2
retry_wait_seconds: 60
timeout_minutes: 10
retry_wait_seconds: 30
max_attempts: 3
command: yarn tests:ios:pod:install

Expand Down Expand Up @@ -168,9 +168,7 @@ jobs:

- name: Detox Test
timeout-minutes: 10
run: |
cd tests
./node_modules/.bin/nyc ./node_modules/.bin/detox test --debug-synchronization 200 --configuration ios.sim.debug
run: yarn tests:ios:test-cover

- name: Compress Simulator Log
if: always()
Expand Down
8 changes: 8 additions & 0 deletions .spellcheck.dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Analytics
analytics
APIs
APIs.
AppAttest
AppCheck
APNs
AirPods
async
Expand Down Expand Up @@ -42,7 +44,9 @@ Deprecations
Detox
DEVEX
Diarmid
DeviceCheck
dropdown
e2e
EEA
Ehesp
enum
Expand All @@ -55,6 +59,7 @@ firebase-ios-sdk
Firestore
getIdToken
GDPR
GDPR-compliant
globals
Gradle
gradle
Expand Down Expand Up @@ -90,6 +95,7 @@ namespaced
natively
NDK
Node.js
non-firebase
NoSQL
Notifee
NPE
Expand Down Expand Up @@ -121,6 +127,7 @@ RN60
RN61
RNFB
RNFirebase
SafetyNet
Salakar
scalable
scrollable
Expand Down Expand Up @@ -150,6 +157,7 @@ uid
uncomment
unhandled
unsubscriber
untampered
utils
Utils
v5
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ The main package that you interface with is `App` (`@react-native-firebase/app`)
| -------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| [Analytics](/packages/analytics) | [![badge](https://img.shields.io/npm/dm/@react-native-firebase/analytics.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-firebase/analytics) |
| [App](/packages/app) | [![badge](https://img.shields.io/npm/dm/@react-native-firebase/app.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-firebase/app) |
| [AppCheck](/packages/app-check) | [![badge](https://img.shields.io/npm/dm/@react-native-firebase/app-check.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-firebase/app-check) |
| [Authentication](/packages/auth) | [![badge](https://img.shields.io/npm/dm/@react-native-firebase/auth.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-firebase/auth) |
| [Cloud Firestore](/packages/firestore) | [![badge](https://img.shields.io/npm/dm/@react-native-firebase/firestore.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-firebase/firestore) |
| [Cloud Functions](/packages/functions) | [![badge](https://img.shields.io/npm/dm/@react-native-firebase/functions.svg?style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@react-native-firebase/functions) |
Expand Down
2 changes: 1 addition & 1 deletion docs/analytics/screen-tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Screen Tracking
description: Setup Firebase Analytics to track your in-app screen flow.
previous: /analytics/usage
next: /
next: /app-check/usage
---

Standard React Native applications run inside a single `Activity`/`ViewController`, meaning any screen changes won't be
Expand Down
94 changes: 94 additions & 0 deletions docs/app-check/usage/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
title: App Check
description: Installation and getting started with App Check.
icon: //static.invertase.io/assets/social/firebase-logo.png
next: /auth/usage
previous: /analytics/screen-tracking
---

# Installation

This module requires that the `@react-native-firebase/app` module is already setup and installed. To install the "app"
module, view the [Getting Started](/) documentation.

```bash
# Install & setup the app module
yarn add @react-native-firebase/app

# Install the app-check module
yarn add @react-native-firebase/app-check

# If you're developing your app using iOS, run this command
cd ios/ && pod install
```

App Check requires you set the minimum iOS Deployment version in `ios/Podfile` to `11.0` or greater.

You may have Xcode compiler errors after including the App Check module, specifically referencing linker problems and missing directories.

You may find excluding the `i386` architecture via an addition to the `ios/Podfile` `post_install` hook like the below works:

```ruby
installer.aggregate_targets.each do |aggregate_target|
aggregate_target.user_project.native_targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
config.build_settings['EXCLUDED_ARCHS'] = 'i386'
end
end
aggregate_target.user_project.save
end
```

# What does it do

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:

- Requests originate from your authentic app
- Requests originate from an authentic, untampered device

This attestation is attached to every request your app makes to your Firebase backend resources.

<Youtube id="Fjj4fmr2t04" />

This App Check module has built-in support for using the following services as attestation providers:

- DeviceCheck on iOS
- SafetyNet on Android

App Check currently works with the following Firebase products:

- Realtime Database
- Cloud Storage
- Cloud Functions (callable functions)

The [official Firebase App Check 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.

# Usage

## Activate

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.

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.

You must call activate prior to calling any firebase back-end services for App Check to function.

## Automatic Data Collection

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.

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

## Using App Check tokens for non-firebase services

The [official documentation](https://firebase.google.com/docs/app-check/web/custom-resource) shows how to use `getToken` to access the current App Check token and then verify it in external services.

## Testing Environments / CI

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.

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:

- including the App Check debug test helper in the test app, along with a change to `DetoxTest` for Android
- by setting an environment variable and initializing the debug provider before firebase configure in `AppDelegate.m` for iOS.
1 change: 1 addition & 0 deletions docs/app/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ for manually initializing secondary Firebase app instances.

Currently, the native Firebase SDKs only provide functionality for creating secondary apps on the following services:

- [AppCheck](/app-check/usage).
- [Authentication](/auth/usage).
- [Realtime Database](/database/usage).
- [Cloud Firestore](/firestore/usage).
Expand Down
2 changes: 1 addition & 1 deletion docs/auth/usage/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Authentication
description: Installation and getting started with Authentication.
icon: //static.invertase.io/assets/firebase/authentication.svg
next: /auth/social-auth
previous: /analytics/screen-tracking
previous: /app-check/usage
---

# Installation
Expand Down
2 changes: 1 addition & 1 deletion docs/releases/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ From version `v6.5.0` until `10.0.0`; all React Native Firebase packages were in

| Package | | |
| ---------------------- | :------------------------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------------------------------------: |
| AdMob | ![hide:badge](https://img.shields.io/npm/v/@react-native-firebase/admob.svg?style=for-the-badge&logo=npm) | [View Release Notes &raquo;](https://github.com/invertase/react-native-firebase/tree/master/packages/admob/CHANGELOG.md) |
| Analytics | ![hide:badge](https://img.shields.io/npm/v/@react-native-firebase/analytics.svg?style=for-the-badge&logo=npm) | [View Release Notes &raquo;](https://github.com/invertase/react-native-firebase/tree/master/packages/analytics/CHANGELOG.md) |
| App | ![hide:badge](https://img.shields.io/npm/v/@react-native-firebase/app.svg?style=for-the-badge&logo=npm) | [View Release Notes &raquo;](https://github.com/invertase/react-native-firebase/tree/master/packages/app/CHANGELOG.md) |
| AppCheck | ![hide:badge](https://img.shields.io/npm/v/@react-native-firebase/app-check.svg?style=for-the-badge&logo=npm) | [View Release Notes &raquo;](https://github.com/invertase/react-native-firebase/tree/master/packages/app-check/CHANGELOG.md) |
| Authentication | ![hide:badge](https://img.shields.io/npm/v/@react-native-firebase/auth.svg?style=for-the-badge&logo=npm) | [View Release Notes &raquo;](https://github.com/invertase/react-native-firebase/tree/master/packages/auth/CHANGELOG.md) |
| Cloud Firestore | ![hide:badge](https://img.shields.io/npm/v/@react-native-firebase/firestore.svg?style=for-the-badge&logo=npm) | [View Release Notes &raquo;](https://github.com/invertase/react-native-firebase/tree/master/packages/firestore/CHANGELOG.md) |
| Cloud Functions | ![hide:badge](https://img.shields.io/npm/v/@react-native-firebase/functions.svg?style=for-the-badge&logo=npm) | [View Release Notes &raquo;](https://github.com/invertase/react-native-firebase/tree/master/packages/functions/CHANGELOG.md) |
Expand Down
4 changes: 4 additions & 0 deletions docs/sidebar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
- - Building an Analytics Funnel
- 'https://blog.theodo.com/2018/01/building-google-analytics-funnel-firebase-react-native'
- '//static.invertase.io/assets/firebase/analytics.svg'
- - App Check
- - - Usage
- '/app-check/usage'
- '//static.invertase.io/assets/social/firebase-logo.png'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked, there is no AppCheck official logo that I can find.

- - Authentication
- - - Usage
- '/auth/usage'
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
"tests:android:test:jacoco-report": "cd tests/android && ./gradlew jacocoAndroidTestReport",
"tests:ios:build": "cd tests && ./node_modules/.bin/detox build --configuration ios.sim.debug",
"tests:ios:build-release": "cd tests && ./node_modules/.bin/detox build --configuration ios.sim.release",
"tests:ios:test": "cd tests && ./node_modules/.bin/detox test --configuration ios.sim.debug --loglevel warn",
"tests:ios:test:debug": "cd tests && ./node_modules/.bin/detox test --configuration ios.sim.debug --loglevel warn --inspect",
"tests:ios:test-reuse": "cd tests && ./node_modules/.bin/detox test --configuration ios.sim.debug --reuse --loglevel warn",
"tests:ios:test-cover": "cd tests && ./node_modules/.bin/nyc ./node_modules/.bin/detox test --configuration ios.sim.debug --loglevel warn",
"tests:ios:test-cover-reuse": "cd tests && node_modules/.bin/nyc ./node_modules/.bin/detox test --configuration ios.sim.debug --reuse --loglevel warn",
"tests:ios:test": "cd tests && SIMCTL_CHILD_FIRAAppCheckDebugToken=698956B2-187B-49C6-9E25-C3F3530EEBAF ./node_modules/.bin/detox test --configuration ios.sim.debug --loglevel warn",
"tests:ios:test:debug": "cd tests && SIMCTL_CHILD_FIRAAppCheckDebugToken=698956B2-187B-49C6-9E25-C3F3530EEBAF ./node_modules/.bin/detox test --configuration ios.sim.debug --loglevel warn --inspect",
"tests:ios:test-reuse": "cd tests && SIMCTL_CHILD_FIRAAppCheckDebugToken=\"698956B2-187B-49C6-9E25-C3F3530EEBAF\" ./node_modules/.bin/detox test --configuration ios.sim.debug --reuse --loglevel warn",
"tests:ios:test-cover": "cd tests && SIMCTL_CHILD_FIRAAppCheckDebugToken=698956B2-187B-49C6-9E25-C3F3530EEBAF ./node_modules/.bin/nyc ./node_modules/.bin/detox test --configuration ios.sim.debug --loglevel warn",
"tests:ios:test-cover-reuse": "cd tests && SIMCTL_CHILD_FIRAAppCheckDebugToken=698956B2-187B-49C6-9E25-C3F3530EEBAF node_modules/.bin/nyc ./node_modules/.bin/detox test --configuration ios.sim.debug --reuse --loglevel warn",
"tests:ios:pod:install": "cd tests && cd ios && rm -rf ReactNativeFirebaseDemo.xcworkspace && rm -f Podfile.lock && pod install --repo-update && cd ..",
"format:markdown": "prettier --write \"docs/**/*.md\""
},
Expand Down
65 changes: 65 additions & 0 deletions packages/app-check/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Built application files
android/*/build/

# Crashlytics configuations
android/com_crashlytics_export_strings.xml

# Local configuration file (sdk path, etc)
android/local.properties

# Gradle generated files
android/.gradle/

# Signing files
android/.signing/

# User-specific configurations
android/.idea/gradle.xml
android/.idea/libraries/
android/.idea/workspace.xml
android/.idea/tasks.xml
android/.idea/.name
android/.idea/compiler.xml
android/.idea/copyright/profiles_settings.xml
android/.idea/encodings.xml
android/.idea/misc.xml
android/.idea/modules.xml
android/.idea/scopes/scope_settings.xml
android/.idea/vcs.xml
android/*.iml

# Xcode
*.pbxuser
*.mode1v3
*.mode2v3
*.perspectivev3
*.xcuserstate
ios/Pods
ios/build
*project.xcworkspace*
*xcuserdata*

# OS-specific files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.dbandroid/gradle
android/gradlew
android/build
android/gradlew.bat
android/gradle/

.idea
coverage
yarn.lock
e2e/
.github
.vscode
.nyc_output
android/.settings
*.coverage.json
.circleci
.eslintignore
32 changes: 32 additions & 0 deletions packages/app-check/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Apache-2.0 License
------------------

Copyright (c) 2016-present Invertase Limited <[email protected]> & Contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this library except in compliance with the License.

You may obtain a copy of the Apache-2.0 License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


Creative Commons Attribution 3.0 License
----------------------------------------

Copyright (c) 2016-present Invertase Limited <[email protected]> & Contributors

Documentation and other instructional materials provided for this project
(including on a separate documentation repository or it's documentation website) are
licensed under the Creative Commons Attribution 3.0 License. Code samples/blocks
contained therein are licensed under the Apache License, Version 2.0 (the "License"), as above.

You may obtain a copy of the Creative Commons Attribution 3.0 License at

https://creativecommons.org/licenses/by/3.0/
Loading