firebase / flutterfire

πŸ”₯ A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.57k stars 3.94k forks source link

πŸ› [APP_CHECK] Instructions for activating the debug provider on IOS don't appear to work #6872

Closed PaulRudin closed 1 year ago

PaulRudin commented 3 years ago

Bug report

I have followed the instructions for activating the debug Appcheck provider here: https://firebase.flutter.dev/docs/app-check/usage/#activating-the-debug-provider-iosmacos but do not see a logged debug token.

App check works fine running on real ios devices, but when I attempt to run on a simulator, I don't get a debug token logged, and I can see in the firebase console that attempts to read the realtime database are being blocked by appcheck.

Steps to reproduce

Steps to reproduce the behavior:

  1. Modify ios/Runner/AppDeletage.swift. If I used exactly the version from the instructions I get build errors. This is the version I'm trying:
    
    import UIKit
    import Flutter

import google_mobile_ads

import Firebase

@UIApplicationMain @objc class AppDelegate: FlutterAppDelegate {

override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { GeneratedPluginRegistrant.register(with: self)

let listTileFactory = ListTileNativeAdFactory()
FLTGoogleMobileAdsPlugin.registerNativeAdFactory(
    self, factoryId: "listTile", nativeAdFactory: listTileFactory)

let providerFactory = AppCheckDebugProviderFactory()
AppCheck.setAppCheckProviderFactory(providerFactory)

return super.application(application, didFinishLaunchingWithOptions: launchOptions)

} }


2. Ensure that your app uses appcheck protected services and that appcheck is enforced.
3. Run the app on a simulator with e.g. `flutter run`
4. Check the logs - there's no debug token printed.

### Expected behavior

I expect a debug appcheck token to be logged.

## Additional context

Appcheck works on real ios devices for the same app.

---

### Flutter doctor

Run `flutter doctor` and paste the output below:

<details><summary>Click To Expand</summary>

flutter doctor Doctor summary (to see all details, run flutter doctor -v): [βœ“] Flutter (Channel stable, 2.2.3, on macOS 11.5.2 20G95 darwin-arm, locale en-GB) [βœ—] Android toolchain - develop for Android devices βœ— Unable to locate Android SDK. Install Android Studio from: https://developer.android.com/studio/index.html On first launch it will assist you in installing the Android SDK components. (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions). If the Android SDK has been installed to a custom location, please use flutter config --android-sdk to update to that location.

[βœ“] Xcode - develop for iOS and macOS [βœ“] Chrome - develop for the web [!] Android Studio (not installed) [βœ“] Connected device (3 available)

! Doctor found issues in 2 categories.


</details>

---

### Flutter dependencies

Run `flutter pub deps -- --style=compact` and paste the output below:

<details><summary>Click To Expand</summary>

Changing current working directory to: /Users/paulrudin/Dropbox/livefpl-ui Dart SDK 2.13.4 Flutter SDK 2.2.3 liveff 0.0.116+64

dependencies:

dev dependencies:

transitive dependencies:



</details>

---
markusaksli-nc commented 3 years ago

Hi @PaulRudin Are there any errors logged? Have you tried using the latest version firebase_app_check: ^0.0.2? Thank you

PaulRudin commented 3 years ago

I have upgraded firebase_app_check to 0.0.2, but the behaviour is the same. There's no error logged.

markusaksli-nc commented 3 years ago

Have you tried the instructions in the firebase docs?

PaulRudin commented 2 years ago

Yeah, so I'd already experimented with those instructions. I've found that adding -FIRDebugEnabled to the launch arguments makes no difference. Adding FirebaseApp.configure() in AppDelegate.swift causes the app to crash after startup (which is perhaps not a surprise as I've already got Firebase.initializeApp(); in my dart code - not sure?)

PaulRudin commented 2 years ago

If I can find time tomorrow I'll try to make a minimal project that exhibits this behaviour... at least then we might have an idea if it's peculiar to something I've done or it's a general problem with flutter/ios/appcheck/emulator/debug tokens

markusaksli-nc commented 2 years ago

There are some general issues with appcheck right now (some of which have been fixed but are pending a new firebase sdk release) so I'll label this based on the report for now. Haven't been able to reproduce this myself though.

AresVampire commented 2 years ago

I am facing the same issue, debug token is not generated. with the latest version 0.0.3

moritzpail commented 2 years ago

I ran into the same issue today ( with firebase_app_check: ^0.0.6+2).

I found that while no debug token is printed to the console when running flutter run the token was printed to the console when running the project directly from Xcode. I am not sure what exactly the issue is, but maybe it helps.

rohan20 commented 2 years ago

For everyone struggling with this issue, what did you end up doing? Not enforcing AppCheck?

Or did you stop using the iOS Simulator for dev?

PaulRudin commented 2 years ago

You don't see the output in the console from flutter run, but if you launch via xcode, then you can see it in the output that xcode shows.

OfirMarom commented 1 year ago

In case this helps anyone, I got the debug token to generate with firebase_app_check v0.0.8. As previously mentioned, the debug token displays when you launch directly from xcode.

In addition, I found that these lines:

let providerFactory = AppCheckDebugProviderFactory()
AppCheck.setAppCheckProviderFactory(providerFactory)

Must occur BEFORE this line:

GeneratedPluginRegistrant.register(with: self)

I have no idea why, but the other way did not generate a token. I suspect it is related to this line in the documentation: "In your debug build before using any Firebase backend services, create and set the App Check debug provider factory".

Lyokone commented 1 year ago

Closing since @OfirMarom response is working