From 2b1eea12c7e1e95e2c63619a676a9460379e80a3 Mon Sep 17 00:00:00 2001 From: Kevin Cheung Date: Mon, 29 Aug 2022 14:03:27 -0700 Subject: [PATCH 1/5] docs(app-check): Add debug provider docs --- docs/app-check/debug-provider.md | 142 +++++++++++++++++++++++++++++-- 1 file changed, 135 insertions(+), 7 deletions(-) diff --git a/docs/app-check/debug-provider.md b/docs/app-check/debug-provider.md index 5efff439b160..4b7594147f5a 100644 --- a/docs/app-check/debug-provider.md +++ b/docs/app-check/debug-provider.md @@ -1,7 +1,9 @@ -Project: /docs/_project.yaml +Project: /docs/app-check/_project.yaml Book: /docs/_book.yaml +page_type: guide - +{% include "docs/app-check/_local_variables.html" %} +{% include "_shared/firebase/_snippet_include_comment.html" %} # Use App Check with the debug provider with Flutter @@ -16,9 +18,135 @@ Warning: The debug provider allows access to your Firebase resources from unverified devices. Don't use the debug provider in production builds of your app, and don't share your debug builds with untrusted parties. -The debug provider does not currently have a Dart API; you'll need to apply the -changes individually for each of your platforms: +## Apple platforms -- [Use App Check with the debug provider on Apple platforms](/docs/app-check/ios/debug-provider) -- [Use App Check with the debug provider on Android](/docs/app-check/android/debug-provider) -- [Use App Check with the debug provider in web apps](/docs/app-check/web/debug-provider) +To use the debug provider while running your app in a simulator interactively +(during development, for example), do the following: + +1. In the file `ios/Runner/AppDelegate.swift` (or `AppDelegate.m`), create and + set the App Check debug provider factory in Debug builds: + + * {Swift} + + ```swift + import UIKit + import Flutter + import Firebase // Add the Firebase import. + + @UIApplicationMain + @objc class AppDelegate: FlutterAppDelegate { + override func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) -> Bool { + // Use the debug provider in Debug builds: + #if DEBUG + let providerFactory = AppCheckDebugProviderFactory() + AppCheck.setAppCheckProviderFactory(providerFactory) + #endif + + GeneratedPluginRegistrant.register(with: self) + return super.application(application, didFinishLaunchingWithOptions: launchOptions) + } + } + ``` + + Tip: Confirm in your Xcode project's Build Settings that it passes the + `DEBUG` flag to the Swift compiler. + + * {Objective-C} + + ```objc + #import "AppDelegate.h" + #import "GeneratedPluginRegistrant.h" + @import Firebase; // Add the Firebase import. + + @implementation AppDelegate + + - (BOOL)application:(UIApplication *)application + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Use the debug provider in Debug builds: + #if DEBUG + FIRAppCheckDebugProviderFactory *providerFactory = [[FIRAppCheckDebugProviderFactory alloc] init]; + [FIRAppCheck setAppCheckProviderFactory:providerFactory]; + #endif + [GeneratedPluginRegistrant registerWithRegistry:self]; + // Override point for customization after application launch. + return [super application:application didFinishLaunchingWithOptions:launchOptions]; + } + + @end + ``` + +1. Enable debug logging in your Xcode project (v11.0 or newer): + + 1. Open **Product > Scheme > Edit scheme**. + 1. Select **Run** from the left menu, then select the **Arguments** tab. + 1. In the **Arguments Passed on Launch** section, add `-FIRDebugEnabled`. + +1. Open `ios/Runner.xcworkspace` with Xcode and run your app in the Simulator. + A local debug token will be logged to the debug output when Firebase tries + to send a request to the backend. For example: + +
[Firebase/AppCheck][I-FAA001001] Firebase App Check Debug Token:
+    123a4567-b89c-12d3-e456-789012345678
+ +{# Google-internal common file: #} +<<../_includes/manage-debug-tokens.md>> + +After you register the token, Firebase backend services will accept it as valid. + +Because this token allows access to your Firebase resources without a +valid device, it is crucial that you keep it private. Don't commit it to a +public repository, and if a registered token is ever compromised, revoke it +immediately in the Firebase console. + +## Android + +The debug provider is not currently supported in Flutter apps on Android. See +[issue #6551](https://github.com/firebase/flutterfire/issues/6551#issuecomment-1225502729) +in GitHub for a workaround. + +## Web + +To use the debug provider while running your app from `localhost` (during +development, for example), do the following: + +Warning: _Do not_ try to enable `localhost` debugging by adding `localhost` to +reCAPTCHA’s allowed domains. Doing so would allow anyone to run your app from +their local machines! + +1. In the file `web/index.html`, enable debug mode by setting + `self.FIREBASE_APPCHECK_DEBUG_TOKEN` to `true`: + + ```html + + + + ... + + + ``` + +1. Run your web app locally and open the browser’s developer tool. In the + debug console, you’ll see a debug token: + +
AppCheck debug token: "123a4567-b89c-12d3-e456-789012345678". You will
+    need to safelist it in the Firebase console for it to work.
+ + This token is stored locally in your browser and will be used whenever you + use your app in the same browser on the same machine. If you want to use the + token in another browser or on another machine, set + `self.FIREBASE_APPCHECK_DEBUG_TOKEN` to the token string instead of `true`. + +{# Google-internal common file: #} +<<../_includes/manage-debug-tokens.md>> + +After you register the token, Firebase backend services will accept it as valid. + +Because this token allows access to your Firebase resources without a +valid device, it is crucial that you keep it private. Don't commit it to a +public repository, and if a registered token is ever compromised, revoke it +immediately in the Firebase console. From 55bb22327ea614705d918132eadbb2210accdbcf Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 27 Sep 2022 14:32:39 +0100 Subject: [PATCH 2/5] docs(app-check): update android debug-provider.md docs --- docs/app-check/debug-provider.md | 36 +++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/docs/app-check/debug-provider.md b/docs/app-check/debug-provider.md index 4b7594147f5a..0f888f160586 100644 --- a/docs/app-check/debug-provider.md +++ b/docs/app-check/debug-provider.md @@ -103,9 +103,39 @@ immediately in the Firebase console. ## Android -The debug provider is not currently supported in Flutter apps on Android. See -[issue #6551](https://github.com/firebase/flutterfire/issues/6551#issuecomment-1225502729) -in GitHub for a workaround. +To use the debug provider while running your Flutter app in an android environment, +implement the following: + +```dart +import 'package:flutter/material.dart'; +import 'package:firebase_core/firebase_core.dart'; + +// Import the firebase_app_check plugin +import 'package:firebase_app_check/firebase_app_check.dart'; + +Future main() async { + WidgetsFlutterBinding.ensureInitialized(); + await Firebase.initializeApp(); + await FirebaseAppCheck.instance.activate( + webRecaptchaSiteKey: 'recaptcha-v3-site-key', + // Set the androidDebugProvider to `true` + androidDebugProvider: true, + ); + runApp(App()); +} + +``` + +A local debug token will be logged to the debug output when Firebase tries +to send a request to the backend. For example: + +
D DebugAppCheckProvider: Enter this debug secret into the allow list in
+the Firebase Console for your project: 123a4567-b89c-12d3-e456-789012345678
+ +{# Google-internal common file: #} +<<../_includes/manage-debug-tokens.md>> + +After you register the token, Firebase backend services will accept it as valid. ## Web From 09f463a7b13dfa5173e9895a248328e02bc8b086 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 27 Sep 2022 14:58:31 +0100 Subject: [PATCH 3/5] docs(app-check): update android debug-provider.md docs --- docs/app-check/debug-provider.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/app-check/debug-provider.md b/docs/app-check/debug-provider.md index 0f888f160586..04394cfd5a6e 100644 --- a/docs/app-check/debug-provider.md +++ b/docs/app-check/debug-provider.md @@ -104,7 +104,20 @@ immediately in the Firebase console. ## Android To use the debug provider while running your Flutter app in an android environment, -implement the following: +do the following: + +Add the following dependencies to your `android/app/build.gradle` file: + +```gradle + +dependencies { + // Add the following dependencies: + implementation 'com.google.firebase:firebase-appcheck-safetynet:16.0.0' + implementation 'com.google.firebase:firebase-appcheck-debug:16.0.0' +} +``` + +Implement the following code in your Flutter application: ```dart import 'package:flutter/material.dart'; From fa2a7fdfa31f9e3df9f66b34098e8b7c87b04878 Mon Sep 17 00:00:00 2001 From: Russell Wheatley Date: Tue, 27 Sep 2022 16:55:35 +0100 Subject: [PATCH 4/5] Update debug-provider.md --- docs/app-check/debug-provider.md | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/docs/app-check/debug-provider.md b/docs/app-check/debug-provider.md index 04394cfd5a6e..ae4e175b56aa 100644 --- a/docs/app-check/debug-provider.md +++ b/docs/app-check/debug-provider.md @@ -103,21 +103,8 @@ immediately in the Firebase console. ## Android -To use the debug provider while running your Flutter app in an android environment, -do the following: - -Add the following dependencies to your `android/app/build.gradle` file: - -```gradle - -dependencies { - // Add the following dependencies: - implementation 'com.google.firebase:firebase-appcheck-safetynet:16.0.0' - implementation 'com.google.firebase:firebase-appcheck-debug:16.0.0' -} -``` - -Implement the following code in your Flutter application: +To use the debug provider while running your Flutter app in an android environment, +implement the following code in your Flutter application: ```dart import 'package:flutter/material.dart'; From 451209e29a7de2c19c423aa6463729f4d96f0bd8 Mon Sep 17 00:00:00 2001 From: Kevin Cheung Date: Tue, 27 Sep 2022 09:44:07 -0700 Subject: [PATCH 5/5] Minor edits --- docs/app-check/debug-provider.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/app-check/debug-provider.md b/docs/app-check/debug-provider.md index ae4e175b56aa..3a08ebbd076d 100644 --- a/docs/app-check/debug-provider.md +++ b/docs/app-check/debug-provider.md @@ -85,8 +85,8 @@ To use the debug provider while running your app in a simulator interactively 1. In the **Arguments Passed on Launch** section, add `-FIRDebugEnabled`. 1. Open `ios/Runner.xcworkspace` with Xcode and run your app in the Simulator. - A local debug token will be logged to the debug output when Firebase tries - to send a request to the backend. For example: + Your app will print a local debug token to the debug output when Firebase + tries to send a request to the backend. For example:
[Firebase/AppCheck][I-FAA001001] Firebase App Check Debug Token:
     123a4567-b89c-12d3-e456-789012345678
@@ -103,7 +103,7 @@ immediately in the Firebase console. ## Android -To use the debug provider while running your Flutter app in an android environment, +To use the debug provider while running your Flutter app in an Android environment, implement the following code in your Flutter application: ```dart @@ -126,7 +126,7 @@ Future main() async { ``` -A local debug token will be logged to the debug output when Firebase tries +Your app will print a local debug token to the debug output when Firebase tries to send a request to the backend. For example:
D DebugAppCheckProvider: Enter this debug secret into the allow list in