From a5ee74399b2a8e2dbc7646ade67af00377b472ae Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 24 Aug 2022 10:49:25 +0100 Subject: [PATCH 01/16] chore(app-check): Update example app and android config for debug use --- .../FlutterFirebaseAppCheckPlugin.java | 7 +++++++ .../example/android/app/build.gradle | 12 +++++++++--- .../example/android/build.gradle | 8 ++++---- .../firebase_app_check/example/lib/main.dart | 19 +++++++++++++++++++ .../firebase_app_check/example/pubspec.yaml | 9 ++++++++- 5 files changed, 47 insertions(+), 8 deletions(-) diff --git a/packages/firebase_app_check/firebase_app_check/android/src/main/java/io/flutter/plugins/firebase/appcheck/FlutterFirebaseAppCheckPlugin.java b/packages/firebase_app_check/firebase_app_check/android/src/main/java/io/flutter/plugins/firebase/appcheck/FlutterFirebaseAppCheckPlugin.java index 3a54e69dc2eb..04d6ec91763a 100644 --- a/packages/firebase_app_check/firebase_app_check/android/src/main/java/io/flutter/plugins/firebase/appcheck/FlutterFirebaseAppCheckPlugin.java +++ b/packages/firebase_app_check/firebase_app_check/android/src/main/java/io/flutter/plugins/firebase/appcheck/FlutterFirebaseAppCheckPlugin.java @@ -74,9 +74,16 @@ private Task activate(Map arguments) { return Tasks.call( cachedThreadPool, () -> { + // To test your app in debug mode, you may uncomment the following + // if(BuildConfig.DEBUG) { + // FirebaseAppCheck firebaseAppCheck = FirebaseAppCheck.getInstance(); + // firebaseAppCheck.installAppCheckProviderFactory( + // DebugAppCheckProviderFactory.getInstance()); + // } else { FirebaseAppCheck firebaseAppCheck = getAppCheck(arguments); firebaseAppCheck.installAppCheckProviderFactory( SafetyNetAppCheckProviderFactory.getInstance()); + // } return null; }); } diff --git a/packages/firebase_app_check/firebase_app_check/example/android/app/build.gradle b/packages/firebase_app_check/firebase_app_check/example/android/app/build.gradle index 4711e57e8d13..d5a68a16cce6 100644 --- a/packages/firebase_app_check/firebase_app_check/example/android/app/build.gradle +++ b/packages/firebase_app_check/firebase_app_check/example/android/app/build.gradle @@ -28,15 +28,16 @@ apply plugin: 'com.google.gms.google-services' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 30 + compileSdkVersion 33 defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "io.flutter.plugins.firebase.appcheck.example" - minSdkVersion 16 - targetSdkVersion 30 + minSdkVersion 19 + targetSdkVersion 33 versionCode flutterVersionCode.toInteger() versionName flutterVersionName + multiDexEnabled true } buildTypes { @@ -51,3 +52,8 @@ android { flutter { source '../..' } + +dependencies { + implementation 'com.google.firebase:firebase-appcheck-safetynet:16.0.0' + implementation 'com.google.firebase:firebase-appcheck-debug:16.0.0' +} diff --git a/packages/firebase_app_check/firebase_app_check/example/android/build.gradle b/packages/firebase_app_check/firebase_app_check/example/android/build.gradle index df146989f8eb..c613764dffda 100644 --- a/packages/firebase_app_check/firebase_app_check/example/android/build.gradle +++ b/packages/firebase_app_check/firebase_app_check/example/android/build.gradle @@ -1,13 +1,13 @@ buildscript { repositories { google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.2' + classpath 'com.android.tools.build:gradle:4.1.3' // START: FlutterFire Configuration - classpath 'com.google.gms:google-services:4.3.10' + classpath 'com.google.gms:google-services:4.3.13' // END: FlutterFire Configuration } } @@ -15,7 +15,7 @@ buildscript { allprojects { repositories { google() - jcenter() + mavenCentral() } } diff --git a/packages/firebase_app_check/firebase_app_check/example/lib/main.dart b/packages/firebase_app_check/firebase_app_check/example/lib/main.dart index 4eda7e7a0fb5..2db8d049e3c7 100644 --- a/packages/firebase_app_check/firebase_app_check/example/lib/main.dart +++ b/packages/firebase_app_check/firebase_app_check/example/lib/main.dart @@ -2,6 +2,7 @@ import 'package:firebase_app_check/firebase_app_check.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:cloud_firestore/cloud_firestore.dart'; import 'firebase_options.dart'; @@ -79,6 +80,24 @@ class _FirebaseAppCheck extends State { body: Center( child: Column( children: [ + ElevatedButton( + onPressed: () async { + // Use this button to check whether the request was validated. + // Gets first document in collection + final doc = await FirebaseFirestore.instance + .collection('flutter-tests') + .limit(1) + .get(); + + if (doc.docs.isNotEmpty) { + setMessage('Document found'); + print('${doc.docs[0].data()}'); + } else { + setMessage('Document not found, please add a document to the collection'); + } + }, + child: const Text('Test App Check validate requests'), + ), ElevatedButton( onPressed: () async { if (kIsWeb) { diff --git a/packages/firebase_app_check/firebase_app_check/example/pubspec.yaml b/packages/firebase_app_check/firebase_app_check/example/pubspec.yaml index 053646a5b585..b8b6ac1411a5 100644 --- a/packages/firebase_app_check/firebase_app_check/example/pubspec.yaml +++ b/packages/firebase_app_check/firebase_app_check/example/pubspec.yaml @@ -14,6 +14,8 @@ dependencies: path: ../ firebase_core: path: ../../../firebase_core/firebase_core + cloud_firestore: + path: ../../../cloud_firestore/cloud_firestore flutter: sdk: flutter @@ -28,6 +30,11 @@ dependency_overrides: path: ../../../firebase_core/firebase_core_platform_interface firebase_core_web: path: ../../../firebase_core/firebase_core_web - + cloud_firestore: + path: ../../../cloud_firestore/cloud_firestore + cloud_firestore_platform_interface: + path: ../../../cloud_firestore/cloud_firestore_platform_interface + cloud_firestore_web: + path: ../../../cloud_firestore/cloud_firestore_web flutter: uses-material-design: true From d0c4cc715f6df115f72cca16bb16ab225ec1b085 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 24 Aug 2022 11:05:31 +0100 Subject: [PATCH 02/16] docs(app-check): note on debug instructions --- .../firebase_app_check/firebase_app_check/example/lib/main.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/firebase_app_check/firebase_app_check/example/lib/main.dart b/packages/firebase_app_check/firebase_app_check/example/lib/main.dart index 2db8d049e3c7..bb626c5cd60d 100644 --- a/packages/firebase_app_check/firebase_app_check/example/lib/main.dart +++ b/packages/firebase_app_check/firebase_app_check/example/lib/main.dart @@ -8,6 +8,8 @@ import 'firebase_options.dart'; const kWebRecaptchaSiteKey = '6Lemcn0dAAAAABLkf6aiiHvpGD6x-zF3nOSDU2M8'; +// For iOS debug instructions, please visit: https://github.com/firebase/flutterfire/issues/8969#issuecomment-1202544521 +// For android debug instructions, please visit: https://github.com/firebase/flutterfire/issues/6551#issuecomment-1225502729 Future main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform); From b8b738a09e4e95f782125470e2885a08ad02a8e8 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 24 Aug 2022 11:37:11 +0100 Subject: [PATCH 03/16] chore(app-check): format & resolve analyze issue --- .../firebase_app_check/example/lib/main.dart | 3 ++- .../firebase_app_check/example/pubspec.yaml | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/firebase_app_check/firebase_app_check/example/lib/main.dart b/packages/firebase_app_check/firebase_app_check/example/lib/main.dart index bb626c5cd60d..b21efa42a672 100644 --- a/packages/firebase_app_check/firebase_app_check/example/lib/main.dart +++ b/packages/firebase_app_check/firebase_app_check/example/lib/main.dart @@ -95,7 +95,8 @@ class _FirebaseAppCheck extends State { setMessage('Document found'); print('${doc.docs[0].data()}'); } else { - setMessage('Document not found, please add a document to the collection'); + setMessage( + 'Document not found, please add a document to the collection'); } }, child: const Text('Test App Check validate requests'), diff --git a/packages/firebase_app_check/firebase_app_check/example/pubspec.yaml b/packages/firebase_app_check/firebase_app_check/example/pubspec.yaml index b8b6ac1411a5..ed174860c2c1 100644 --- a/packages/firebase_app_check/firebase_app_check/example/pubspec.yaml +++ b/packages/firebase_app_check/firebase_app_check/example/pubspec.yaml @@ -24,17 +24,17 @@ dependency_overrides: path: ../../../firebase_app_check/firebase_app_check_platform_interface firebase_app_check_web: path: ../../../firebase_app_check/firebase_app_check_web - firebase_core: - path: ../../../firebase_core/firebase_core - firebase_core_platform_interface: - path: ../../../firebase_core/firebase_core_platform_interface - firebase_core_web: - path: ../../../firebase_core/firebase_core_web cloud_firestore: path: ../../../cloud_firestore/cloud_firestore cloud_firestore_platform_interface: path: ../../../cloud_firestore/cloud_firestore_platform_interface cloud_firestore_web: path: ../../../cloud_firestore/cloud_firestore_web + firebase_core: + path: ../../../firebase_core/firebase_core + firebase_core_platform_interface: + path: ../../../firebase_core/firebase_core_platform_interface + firebase_core_web: + path: ../../../firebase_core/firebase_core_web flutter: uses-material-design: true From f08d242b8ace4183db9f0782546c83cbd5972614 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 24 Aug 2022 12:20:13 +0100 Subject: [PATCH 04/16] chore(app-check): format & resolve analyze issue --- .../firebase_app_check/example/lib/main.dart | 3 ++- .../firebase_app_check/example/pubspec.yaml | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/firebase_app_check/firebase_app_check/example/lib/main.dart b/packages/firebase_app_check/firebase_app_check/example/lib/main.dart index b21efa42a672..e0ce54e9430d 100644 --- a/packages/firebase_app_check/firebase_app_check/example/lib/main.dart +++ b/packages/firebase_app_check/firebase_app_check/example/lib/main.dart @@ -96,7 +96,8 @@ class _FirebaseAppCheck extends State { print('${doc.docs[0].data()}'); } else { setMessage( - 'Document not found, please add a document to the collection'); + 'Document not found, please add a document to the collection', + ); } }, child: const Text('Test App Check validate requests'), diff --git a/packages/firebase_app_check/firebase_app_check/example/pubspec.yaml b/packages/firebase_app_check/firebase_app_check/example/pubspec.yaml index ed174860c2c1..fe05279cabfa 100644 --- a/packages/firebase_app_check/firebase_app_check/example/pubspec.yaml +++ b/packages/firebase_app_check/firebase_app_check/example/pubspec.yaml @@ -9,27 +9,27 @@ environment: sdk: ">=2.16.0 <3.0.0" dependencies: + cloud_firestore: + path: ../../../cloud_firestore/cloud_firestore cupertino_icons: ^0.1.2 firebase_app_check: path: ../ firebase_core: path: ../../../firebase_core/firebase_core - cloud_firestore: - path: ../../../cloud_firestore/cloud_firestore flutter: sdk: flutter dependency_overrides: - firebase_app_check_platform_interface: - path: ../../../firebase_app_check/firebase_app_check_platform_interface - firebase_app_check_web: - path: ../../../firebase_app_check/firebase_app_check_web cloud_firestore: path: ../../../cloud_firestore/cloud_firestore cloud_firestore_platform_interface: path: ../../../cloud_firestore/cloud_firestore_platform_interface cloud_firestore_web: path: ../../../cloud_firestore/cloud_firestore_web + firebase_app_check_platform_interface: + path: ../../../firebase_app_check/firebase_app_check_platform_interface + firebase_app_check_web: + path: ../../../firebase_app_check/firebase_app_check_web firebase_core: path: ../../../firebase_core/firebase_core firebase_core_platform_interface: From 0fb6f44d28353f8a9cde894e12041dc066a21055 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 24 Aug 2022 12:53:09 +0100 Subject: [PATCH 05/16] chore: format --- .../FlutterFirebaseAppCheckPlugin.java | 166 +++++++++--------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/packages/firebase_app_check/firebase_app_check/android/src/main/java/io/flutter/plugins/firebase/appcheck/FlutterFirebaseAppCheckPlugin.java b/packages/firebase_app_check/firebase_app_check/android/src/main/java/io/flutter/plugins/firebase/appcheck/FlutterFirebaseAppCheckPlugin.java index d896bb12ea4e..9d71a4635e0b 100644 --- a/packages/firebase_app_check/firebase_app_check/android/src/main/java/io/flutter/plugins/firebase/appcheck/FlutterFirebaseAppCheckPlugin.java +++ b/packages/firebase_app_check/firebase_app_check/android/src/main/java/io/flutter/plugins/firebase/appcheck/FlutterFirebaseAppCheckPlugin.java @@ -28,7 +28,7 @@ import java.util.Objects; public class FlutterFirebaseAppCheckPlugin - implements FlutterFirebasePlugin, FlutterPlugin, MethodCallHandler { + implements FlutterFirebasePlugin, FlutterPlugin, MethodCallHandler { private static final String METHOD_CHANNEL_NAME = "plugins.flutter.io/firebase_app_check"; private final Map streamHandlers = new HashMap<>(); @@ -75,23 +75,23 @@ private Task activate(Map arguments) { TaskCompletionSource taskCompletionSource = new TaskCompletionSource<>(); cachedThreadPool.execute( - () -> { - try { - // To test your app in debug mode, you may uncomment the following - // if(BuildConfig.DEBUG) { - // FirebaseAppCheck firebaseAppCheck = FirebaseAppCheck.getInstance(); - // firebaseAppCheck.installAppCheckProviderFactory( - // DebugAppCheckProviderFactory.getInstance()); - // } else { - FirebaseAppCheck firebaseAppCheck = getAppCheck(arguments); - firebaseAppCheck.installAppCheckProviderFactory( - SafetyNetAppCheckProviderFactory.getInstance()); - // } - taskCompletionSource.setResult(null); - } catch (Exception e) { - taskCompletionSource.setException(e); - } - }); + () -> { + try { + // To test your app in debug mode, you may uncomment the following + // if(BuildConfig.DEBUG) { + // FirebaseAppCheck firebaseAppCheck = FirebaseAppCheck.getInstance(); + // firebaseAppCheck.installAppCheckProviderFactory( + // DebugAppCheckProviderFactory.getInstance()); + // } else { + FirebaseAppCheck firebaseAppCheck = getAppCheck(arguments); + firebaseAppCheck.installAppCheckProviderFactory( + SafetyNetAppCheckProviderFactory.getInstance()); + // } + taskCompletionSource.setResult(null); + } catch (Exception e) { + taskCompletionSource.setException(e); + } + }); return taskCompletionSource.getTask(); } @@ -100,17 +100,17 @@ private Task> getToken(Map arguments) { TaskCompletionSource> taskCompletionSource = new TaskCompletionSource<>(); cachedThreadPool.execute( - () -> { - try { - FirebaseAppCheck firebaseAppCheck = getAppCheck(arguments); - Boolean forceRefresh = (Boolean) Objects.requireNonNull(arguments.get("forceRefresh")); - AppCheckTokenResult tokenResult = Tasks.await(firebaseAppCheck.getToken(forceRefresh)); - - taskCompletionSource.setResult(tokenResultToMap(tokenResult)); - } catch (Exception e) { - taskCompletionSource.setException(e); - } - }); + () -> { + try { + FirebaseAppCheck firebaseAppCheck = getAppCheck(arguments); + Boolean forceRefresh = (Boolean) Objects.requireNonNull(arguments.get("forceRefresh")); + AppCheckTokenResult tokenResult = Tasks.await(firebaseAppCheck.getToken(forceRefresh)); + + taskCompletionSource.setResult(tokenResultToMap(tokenResult)); + } catch (Exception e) { + taskCompletionSource.setException(e); + } + }); return taskCompletionSource.getTask(); } @@ -119,18 +119,18 @@ private Task setTokenAutoRefreshEnabled(Map arguments) { TaskCompletionSource taskCompletionSource = new TaskCompletionSource<>(); cachedThreadPool.execute( - () -> { - try { - FirebaseAppCheck firebaseAppCheck = getAppCheck(arguments); - Boolean isTokenAutoRefreshEnabled = - (Boolean) Objects.requireNonNull(arguments.get("isTokenAutoRefreshEnabled")); - firebaseAppCheck.setTokenAutoRefreshEnabled(isTokenAutoRefreshEnabled); - - taskCompletionSource.setResult(null); - } catch (Exception e) { - taskCompletionSource.setException(e); - } - }); + () -> { + try { + FirebaseAppCheck firebaseAppCheck = getAppCheck(arguments); + Boolean isTokenAutoRefreshEnabled = + (Boolean) Objects.requireNonNull(arguments.get("isTokenAutoRefreshEnabled")); + firebaseAppCheck.setTokenAutoRefreshEnabled(isTokenAutoRefreshEnabled); + + taskCompletionSource.setResult(null); + } catch (Exception e) { + taskCompletionSource.setException(e); + } + }); return taskCompletionSource.getTask(); } @@ -139,23 +139,23 @@ private Task registerTokenListener(Map arguments) { TaskCompletionSource taskCompletionSource = new TaskCompletionSource<>(); cachedThreadPool.execute( - () -> { - try { - String appName = (String) Objects.requireNonNull(arguments.get("appName")); - FirebaseAppCheck firebaseAppCheck = getAppCheck(arguments); - - final TokenChannelStreamHandler handler = - new TokenChannelStreamHandler(firebaseAppCheck); - final String name = METHOD_CHANNEL_NAME + "/token/" + appName; - final EventChannel channel = new EventChannel(messenger, name); - channel.setStreamHandler(handler); - streamHandlers.put(channel, handler); - - taskCompletionSource.setResult(name); - } catch (Exception e) { - taskCompletionSource.setException(e); - } - }); + () -> { + try { + String appName = (String) Objects.requireNonNull(arguments.get("appName")); + FirebaseAppCheck firebaseAppCheck = getAppCheck(arguments); + + final TokenChannelStreamHandler handler = + new TokenChannelStreamHandler(firebaseAppCheck); + final String name = METHOD_CHANNEL_NAME + "/token/" + appName; + final EventChannel channel = new EventChannel(messenger, name); + channel.setStreamHandler(handler); + streamHandlers.put(channel, handler); + + taskCompletionSource.setResult(name); + } catch (Exception e) { + taskCompletionSource.setException(e); + } + }); return taskCompletionSource.getTask(); } @@ -183,17 +183,17 @@ public void onMethodCall(MethodCall call, @NonNull final Result result) { } methodCallTask.addOnCompleteListener( - task -> { - if (task.isSuccessful()) { - result.success(task.getResult()); - } else { - Exception exception = task.getException(); - result.error( - "firebase_app_check", - exception != null ? exception.getMessage() : null, - getExceptionDetails(exception)); - } - }); + task -> { + if (task.isSuccessful()) { + result.success(task.getResult()); + } else { + Exception exception = task.getException(); + result.error( + "firebase_app_check", + exception != null ? exception.getMessage() : null, + getExceptionDetails(exception)); + } + }); } private Map getExceptionDetails(@Nullable Exception exception) { @@ -212,13 +212,13 @@ public Task> getPluginConstantsForFirebaseApp(FirebaseApp fi TaskCompletionSource> taskCompletionSource = new TaskCompletionSource<>(); cachedThreadPool.execute( - () -> { - try { - taskCompletionSource.setResult(null); - } catch (Exception e) { - taskCompletionSource.setException(e); - } - }); + () -> { + try { + taskCompletionSource.setResult(null); + } catch (Exception e) { + taskCompletionSource.setException(e); + } + }); return taskCompletionSource.getTask(); } @@ -228,13 +228,13 @@ public Task didReinitializeFirebaseCore() { TaskCompletionSource taskCompletionSource = new TaskCompletionSource<>(); cachedThreadPool.execute( - () -> { - try { - taskCompletionSource.setResult(null); - } catch (Exception e) { - taskCompletionSource.setException(e); - } - }); + () -> { + try { + taskCompletionSource.setResult(null); + } catch (Exception e) { + taskCompletionSource.setException(e); + } + }); return taskCompletionSource.getTask(); } From 74b1aa70ccfd4d8ae0dcf448b5d2e974cedf21bb Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 24 Aug 2022 12:54:42 +0100 Subject: [PATCH 06/16] chore(app-check): spelling --- .../firebase_app_check/firebase_app_check/example/lib/main.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_app_check/firebase_app_check/example/lib/main.dart b/packages/firebase_app_check/firebase_app_check/example/lib/main.dart index e0ce54e9430d..2981aa4dfc79 100644 --- a/packages/firebase_app_check/firebase_app_check/example/lib/main.dart +++ b/packages/firebase_app_check/firebase_app_check/example/lib/main.dart @@ -100,7 +100,7 @@ class _FirebaseAppCheck extends State { ); } }, - child: const Text('Test App Check validate requests'), + child: const Text('Test App Check validates requests'), ), ElevatedButton( onPressed: () async { From aba038947df236f7873d51cd63f62300bb9f4480 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 24 Aug 2022 12:55:32 +0100 Subject: [PATCH 07/16] chore(app-check): wording --- .../firebase_app_check/example/lib/main.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/firebase_app_check/firebase_app_check/example/lib/main.dart b/packages/firebase_app_check/firebase_app_check/example/lib/main.dart index 2981aa4dfc79..cc7f03ada646 100644 --- a/packages/firebase_app_check/firebase_app_check/example/lib/main.dart +++ b/packages/firebase_app_check/firebase_app_check/example/lib/main.dart @@ -86,14 +86,14 @@ class _FirebaseAppCheck extends State { onPressed: () async { // Use this button to check whether the request was validated. // Gets first document in collection - final doc = await FirebaseFirestore.instance + final result = await FirebaseFirestore.instance .collection('flutter-tests') .limit(1) .get(); - if (doc.docs.isNotEmpty) { + if (result.docs.isNotEmpty) { setMessage('Document found'); - print('${doc.docs[0].data()}'); + print('${result.docs[0].data()}'); } else { setMessage( 'Document not found, please add a document to the collection', From af4efe327c36be6f374a2c8fd0d0d823a71b61a1 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Wed, 24 Aug 2022 12:56:08 +0100 Subject: [PATCH 08/16] chore(app-check): wording --- .../firebase_app_check/firebase_app_check/example/lib/main.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_app_check/firebase_app_check/example/lib/main.dart b/packages/firebase_app_check/firebase_app_check/example/lib/main.dart index cc7f03ada646..22640af7d763 100644 --- a/packages/firebase_app_check/firebase_app_check/example/lib/main.dart +++ b/packages/firebase_app_check/firebase_app_check/example/lib/main.dart @@ -84,7 +84,7 @@ class _FirebaseAppCheck extends State { children: [ ElevatedButton( onPressed: () async { - // Use this button to check whether the request was validated. + // Use this button to check whether the request was validated on the Firebase console // Gets first document in collection final result = await FirebaseFirestore.instance .collection('flutter-tests') From df013a7a0561d8edfbce2b1fbc5abb87ea3924ec Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Mon, 12 Sep 2022 16:24:15 +0100 Subject: [PATCH 09/16] feat(app-check): new "androidDebugProvider" API --- .../FlutterFirebaseAppCheckPlugin.java | 22 ++++++++++--------- .../android/app/src/main/AndroidManifest.xml | 4 +++- .../firebase_app_check/example/lib/main.dart | 5 +++-- .../lib/src/firebase_app_check.dart | 10 +++++++-- .../method_channel_firebase_app_check.dart | 5 ++++- ...platform_interface_firebase_app_check.dart | 3 ++- .../lib/firebase_app_check_web.dart | 3 ++- 7 files changed, 34 insertions(+), 18 deletions(-) diff --git a/packages/firebase_app_check/firebase_app_check/android/src/main/java/io/flutter/plugins/firebase/appcheck/FlutterFirebaseAppCheckPlugin.java b/packages/firebase_app_check/firebase_app_check/android/src/main/java/io/flutter/plugins/firebase/appcheck/FlutterFirebaseAppCheckPlugin.java index 9d71a4635e0b..851714440c36 100644 --- a/packages/firebase_app_check/firebase_app_check/android/src/main/java/io/flutter/plugins/firebase/appcheck/FlutterFirebaseAppCheckPlugin.java +++ b/packages/firebase_app_check/firebase_app_check/android/src/main/java/io/flutter/plugins/firebase/appcheck/FlutterFirebaseAppCheckPlugin.java @@ -14,6 +14,7 @@ import com.google.firebase.FirebaseApp; import com.google.firebase.appcheck.AppCheckTokenResult; import com.google.firebase.appcheck.FirebaseAppCheck; +import com.google.firebase.appcheck.debug.DebugAppCheckProviderFactory; import com.google.firebase.appcheck.safetynet.SafetyNetAppCheckProviderFactory; import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.plugin.common.BinaryMessenger; @@ -77,16 +78,17 @@ private Task activate(Map arguments) { cachedThreadPool.execute( () -> { try { - // To test your app in debug mode, you may uncomment the following - // if(BuildConfig.DEBUG) { - // FirebaseAppCheck firebaseAppCheck = FirebaseAppCheck.getInstance(); - // firebaseAppCheck.installAppCheckProviderFactory( - // DebugAppCheckProviderFactory.getInstance()); - // } else { - FirebaseAppCheck firebaseAppCheck = getAppCheck(arguments); - firebaseAppCheck.installAppCheckProviderFactory( - SafetyNetAppCheckProviderFactory.getInstance()); - // } + boolean debug = (boolean) Objects.requireNonNull(arguments.get("androidDebugProvider")); + + if (debug) { + FirebaseAppCheck firebaseAppCheck = FirebaseAppCheck.getInstance(); + firebaseAppCheck.installAppCheckProviderFactory( + DebugAppCheckProviderFactory.getInstance()); + } else { + FirebaseAppCheck firebaseAppCheck = getAppCheck(arguments); + firebaseAppCheck.installAppCheckProviderFactory( + SafetyNetAppCheckProviderFactory.getInstance()); + } taskCompletionSource.setResult(null); } catch (Exception e) { taskCompletionSource.setException(e); diff --git a/packages/firebase_app_check/firebase_app_check/example/android/app/src/main/AndroidManifest.xml b/packages/firebase_app_check/firebase_app_check/example/android/app/src/main/AndroidManifest.xml index 7a4e2a00194c..b0578ac80d68 100644 --- a/packages/firebase_app_check/firebase_app_check/example/android/app/src/main/AndroidManifest.xml +++ b/packages/firebase_app_check/firebase_app_check/example/android/app/src/main/AndroidManifest.xml @@ -9,7 +9,9 @@ android:theme="@style/LaunchTheme" android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode" android:hardwareAccelerated="true" - android:windowSoftInputMode="adjustResize"> + android:windowSoftInputMode="adjustResize" + android:exported="true" + >