Skip to content

Commit

Permalink
feat(app_check, android): add option to use FIREBASE_APP_CHECK_DEBUG_…
Browse files Browse the repository at this point in the history
…TOKEN env variable as debug token on Android
  • Loading branch information
xVemu committed Apr 19, 2024
1 parent 2b84feb commit 628ca94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ android {
defaultConfig {
minSdk 19
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField "String", "FIREBASE_APP_CHECK_DEBUG_TOKEN", "\"${System.env.FIREBASE_APP_CHECK_DEBUG_TOKEN}\""
}

compileOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,32 @@
package io.flutter.plugins.firebase.appcheck;

import androidx.annotation.Keep;

import com.google.firebase.appcheck.debug.InternalDebugSecretProvider;
import com.google.firebase.components.Component;
import com.google.firebase.components.ComponentRegistrar;
import com.google.firebase.platforminfo.LibraryVersionComponent;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@Keep
public class FlutterFirebaseAppRegistrar implements ComponentRegistrar {
private static final String DEBUG_SECRET_NAME = "fire-app-check-debug-secret";

@Override
public List<Component<?>> getComponents() {
return Collections.<Component<?>>singletonList(
LibraryVersionComponent.create(BuildConfig.LIBRARY_NAME, BuildConfig.LIBRARY_VERSION));
Component<?> library = LibraryVersionComponent.create(BuildConfig.LIBRARY_NAME,
BuildConfig.LIBRARY_VERSION);

if (BuildConfig.FIREBASE_APP_CHECK_DEBUG_TOKEN == null)
return Collections.<Component<?>>singletonList(library);

Component<InternalDebugSecretProvider> debugSecretProvider = Component.builder(InternalDebugSecretProvider.class)
.name(DEBUG_SECRET_NAME)
.factory(container -> () -> BuildConfig.FIREBASE_APP_CHECK_DEBUG_TOKEN).build();

return Arrays.<Component<?>>asList(library, debugSecretProvider);
}
}

0 comments on commit 628ca94

Please sign in to comment.