Repository navigation
Conversation
…r 3.50 Flutter 3.50 registers firebase_core before firebase_app_check. firebase_core configures Firebase during registration, and the Apple SDK creates the App Check provider at that point from whichever factory is installed. The plugin installed its factory later, so activate() reconfigured a provider the SDK never used. firebase_core now lets firebase_app_check install its factory immediately before FirebaseApp.configure(). Fixes #18966
There was a problem hiding this comment.
Code Review
This pull request ensures that the Firebase App Check provider factory is installed on iOS before FirebaseApp.configure() is called. Since firebase_core is registered before firebase_app_check, a dynamic lookup helper installAppCheckProviderFactoryIfLinked was added to FLTFirebaseCorePlugin to invoke installProviderFactory on FirebaseAppCheckPlugin via Objective-C selectors if the plugin is linked. Additionally, an integration test was added to verify that getToken correctly uses the provider passed to activate on iOS simulators. There are no review comments, so I have no feedback to provide.
| /// `FirebaseApp.configure()` and keeps that provider. `activate()` | ||
| /// reconfigures the provider this factory handed out, so there must only | ||
| /// ever be one factory. | ||
| static let sharedProviderFactory = FlutterAppCheckProviderFactory() |
There was a problem hiding this comment.
Optional, could be a follow-up. AppCheck is created eagerly for every app, so when providers[app.name] is nil in FlutterAppCheckProviderFactory.configure (line 354), this factory never handed a provider to that app's AppCheck. The wrapper made there is never asked for a token, yet activate() still completes. That is what happens in the two cases listed under Limits (FirebaseApp.configure() in the AppDelegate, #18613, and a new firebase_app_check with an older firebase_core). Could that branch log something like "App Check for was configured before firebase_app_check installed its provider factory, so the Apple provider passed to activate() is not used (see #18613)"? Apps following the native workaround from #18614 would see it on every launch, which is accurate for them, and everyone else would get a console line instead of only a 403 later.
|
thank you for this pr. |
Description
On iOS and macOS with Flutter 3.50,
FirebaseAppCheck.instance.activate()no longer changes the provider the native SDK uses. On a simulator the SDK keeps a debug provider with a random token and ignoresAppleDebugProvider(debugToken:). On a device it keeps DeviceCheck when App Attest was requested.Cause. Flutter 3.50 registers plugins dependencies first, so
firebase_corenow registers beforefirebase_app_check. Flutter 3.47 and earlier sorted by name, which putfirebase_app_checkfirst.firebase_corecallsFirebaseApp.configure()during registration when aGoogleService-Info.plistis present. The Apple SDK creates App Check during configure and keeps the provider from whichever factory is installed at that moment. The plugin installed its factory only when it registered, which is now too late, soactivate()reconfigured a provider the SDK never asks for a token.Fix.
firebase_app_check: the plugin class has a fixed Objective-C name, one shared provider factory, and a staticinstallProviderFactory().firebase_core: immediately beforeFirebaseApp.configure(), look the App Check plugin up by name and callinstallProviderFactory(). There is no compile-time dependency onfirebase_app_check, and nothing happens when that plugin is not in the app.The macOS sources are symlinks to the iOS files, so both platforms get the change. There is no Dart API change and no generated code change.
Limits.
firebase_app_checkwith an olderfirebase_corebehaves as it does today.FirebaseApp.configure()in its AppDelegate before the plugins register is not covered. That is [firebase_app_check] iOS: activate() providers are silently ignored when FirebaseApp.configure() runs in AppDelegate (firebase-ios-sdk >= 12.15.0 default provider factory) #18613.Related Issues
Fixes #18966
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]).This will ensure a smooth and quick review process. Updating the
pubspec.yamland changelogs is not required.///).melos run analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?
Test plan
New e2e test in the App Check example,
getToken uses the provider passed to activate. It runs on the iOS simulator only. It activates App Attest and expectsgetToken(true)to fail with an App Attest error. No simulator supports App Attest, so that error appears only when the provider passed toactivate()is the one the SDK uses.Run locally on Flutter 3.50.0:
main.activate(AppleDebugProvider(debugToken:))activate(). Without the fix it creates a random token first.flutter build ios --release --no-codesignfirebase_corelooks up.flutter_plugin_tools format,validate-formatting.shmelos run check-license-headerflutter_plugin_tools analyzeNot run: a physical device, a successful token exchange against a registered debug token, and the Android, web, and Windows e2e. The new test is skipped on those platforms.