As the docs are not clear about some things, I came to ask you guys here.
So, Appcheck has been a big pain for me to implement on flutter for 2 weeks now, and when using the Debug tokens in my app on ios or Android I end up with a lot of unexpected behavior.
here's an example from my Android & ios projects where I place the token providers note that I am using flutter:
main.dart
void main() async {
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
MobileAds.instance.initialize();
// preserves splash screen
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
await FirebaseAppCheck.instance.activate(
webRecaptchaSiteKey: 'recaptcha-v3-site-key',
androidProvider:
kReleaseMode ? AndroidProvider.playIntegrity : AndroidProvider.debug,
appleProvider: kReleaseMode ? AppleProvider.deviceCheck : AppleProvider.debug
);
ruApp(...);
}
Android MainActivity.kt
package com.baroraproject.app.barora
//
import android.os.Bundle
import com.google.firebase.FirebaseApp
import com.google.firebase.appcheck.FirebaseAppCheck
import com.google.firebase.appcheck.debug.DebugAppCheckProviderFactory
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity(){
override fun onCreate(savedInstanceState: Bundle?) {
if (BuildConfig.DEBUG) {
FirebaseApp.initializeApp(/*context=*/this)
val firebaseAppCheck = FirebaseAppCheck.getInstance()
firebaseAppCheck.installAppCheckProviderFactory(
DebugAppCheckProviderFactory.getInstance()
)
}
super.onCreate(savedInstanceState)
}
}
IOS Runner/AppDelegeate.swift
import UIKit
import Flutter
import awesome_notifications
import shared_preferences_foundation
import FirebaseCore
import FirebaseAppCheck
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// This function registers the desired plugins to be used within a notification background action
SwiftAwesomeNotificationsPlugin.setPluginRegistrantCallback { registry in
SwiftAwesomeNotificationsPlugin.register(
with: registry.registrar(forPlugin: "io.flutter.plugins.awesomenotifications.AwesomeNotificationsPlugin")!)
SharedPreferencesPlugin.register(
with: registry.registrar(forPlugin: "io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin")!)
}
// Use the debug provider in Debug builds:
#if DEBUG
let providerFactory = AppCheckDebugProviderFactory()
AppCheck.setAppCheckProviderFactory(providerFactory)
#endif
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
my questions are:
1- Should I Remove the debug provider code after I get the debug token logged and stored in Firebase?
2- When does the app check debug token refresh or change? and how do I prevent that from happening?
3- How should I go about keeping the app check debug provider codes outside of my release build? As the Debug statements don't work and when I release I would have to comment on the code that has to do with app check, clean, and rebuild.