firebase Flutter Appcheck(非调试)权限不足

svmlkihl  于 2023-01-21  发布在  Flutter
关注(0)|答案(1)|浏览(148)

在过去的几天里,我一直在尝试让AppCheck在Flutter中正常工作,同时使用AndroidProvider.playIntegrity,但我一直得到权限错误。由于AppCheck Firestore已经设置为enforced,当我使用AndroidProvider.debug时(插入调试令牌后),一切都很好。当我停止使用调试时,这就是问题所在。
错误信息

W/Firestore( 5050): (24.4.1) [Firestore]: Listen for Query(target=Query(users/abc123/foo order by __name__);limitType=LIMIT_TO_FIRST) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
W/Firestore( 5050): (24.4.1) [Firestore]: Listen for Query(target=Query(users/abc123 order by __name__);limitType=LIMIT_TO_FIRST) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
    • 主省道**
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();

// Trying to use AndroidProvider.playIntegrity
await FirebaseAppCheck.instance.activate();

// Works fine in debug
// await FirebaseAppCheck.instance.activate(
//   androidProvider: AndroidProvider.debug
// );
    • 安卓/应用程序/构建版本. gradle**
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.google.gms.google-services'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdkVersion 33
    ndkVersion flutter.ndkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.foo.bar"
        // You can update the following values to match your application needs.
        // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-build-configuration.
        minSdkVersion 26
        targetSdkVersion 31
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
            storePassword keystoreProperties['storePassword']
        }
    }
    buildTypes {
        release {
            signingConfig signingConfigs.release
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
    implementation platform('com.google.firebase:firebase-bom:31.1.1')
    implementation 'com.google.firebase:firebase-analytics'

    // Tried enabling this but nothing  really happened
    // implementation 'com.google.firebase:firebase-appcheck-playintegrity'

    // Facebook
    implementation 'com.facebook.android:facebook-android-sdk:latest.release'

    // flutter_local_notifications
    coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:1.0.4")
}
    • Firestore规则**(用于开发目的)
rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
  
    function isAuth() {
      return request.auth != null;
    }
    
    function isDev() {
      return isAuth() && request.auth.token.email in [
        'testemail@gmail.com'
      ];
    }

    match /{document=**} {
      allow read, write: if isDev();
    }
  }
}

我想可能是缺少了一些依赖项,所以我尝试在我的build. gradle文件中添加

dependencies {
    ...

    // Tried enabling this but nothing really happened so I commented it out
    // implementation 'com.google.firebase:firebase-appcheck-playintegrity'

    ...
}

因为它被添加到Android指令中,但最终注解掉了,因为它什么也没做。
然后,也许它需要是一个实际的版本,所以我创建了一个阿尔法版本在播放控制台,并获得批准后,我下载了应用程序,似乎我仍然不能连接到Firestore。
项目设置和AppCheck PlayIntegrity中的SHA-256指纹取自调试证书、应用签名密钥(Play控制台)和上传密钥(Play控制台)。

    • 顺便说一句,**我将compileSdkVersion设置为33,将targetSdkVersion设置为31。它们应该相同吗?
fbcarpbf

fbcarpbf1#

我也在类似的问题上犯了错。
以下全部、部分或全部都没有帮助:

  • 已弃用 * SafetyNet认证提供程序可在真实的设备上为我工作而不是从PlayStore安装,使用类似以下内容:
import 'package:store_checker/store_checker.dart' as sc;

      final debug = false;
      assert(debug = true);
      final appcheck = FirebaseAppCheck.instance;
      final src = await sc.StoreChecker.getSource;
      await appcheck.activate(
        androidProvider: debug
            ? AndroidProvider.debug
            : src == sc.Source.IS_INSTALLED_FROM_PLAY_STORE
                ? AndroidProvider.playIntegrity
                : AndroidProvider.safetyNet,
      );

我不知道这是否是一件重要的事情,但在我的https://play.google.com/console中,我也去了SetupApp Integrity页面(从侧边栏),并链接了我的Firebase项目,因为它不存在。
我还没有发布一个新的,一个新的构建,看看这是否修复了什么...
可能是你必须用Play Store证书在应用上签名才能让PlayIntegrity工作,我根本没有想通那一条。

相关问题