Skip to content

Commit 84407af

Browse files
WIP: feat(appcheck): Implement initial reCAPTCHA Enterprise provider
This commit introduces the basic structure for the reCAPTCHA Enterprise App Check provider. It's currently a work in progress and not yet ready for review or final integration. - Added `RecaptchaEnterpriseAppCheckProviderFactory`. - Added `FirebaseAppCheckRecaptchaEnterpriseRegistrar`. - Further implementation and testing are required.
1 parent f08e0c7 commit 84407af

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.google.firebase.appcheck.recaptchaenterprise;
2+
3+
import android.app.Application;
4+
import android.content.Context;
5+
6+
import com.google.android.gms.common.annotation.KeepForSdk;
7+
import com.google.firebase.FirebaseApp;
8+
import com.google.firebase.annotations.concurrent.Blocking;
9+
import com.google.firebase.annotations.concurrent.Lightweight;
10+
import com.google.firebase.appcheck.recaptchaenterprise.internal.RecaptchaEnterpriseAppCheckProvider;
11+
import com.google.firebase.appcheck.recaptchaenterprise.internal.SiteKey;
12+
import com.google.firebase.components.Component;
13+
import com.google.firebase.components.ComponentRegistrar;
14+
import com.google.firebase.components.Dependency;
15+
import com.google.firebase.components.Qualified;
16+
import com.google.firebase.platforminfo.LibraryVersionComponent;
17+
18+
import java.util.Arrays;
19+
import java.util.List;
20+
import java.util.concurrent.Executor;
21+
22+
/**
23+
* {@link ComponentRegistrar} for setting up FirebaseAppCheck reCAPTCHA Enterprise's dependency
24+
* injections in Firebase Android Components.
25+
*
26+
* @hide
27+
*/
28+
@KeepForSdk
29+
public class FirebaseAppCheckRecaptchaEnterpriseRegistrar implements ComponentRegistrar {
30+
private static final String LIBRARY_NAME = "fire-app-check-recaptcha-enterprise";
31+
32+
@Override
33+
public List<Component<?>> getComponents() {
34+
Qualified<Executor> liteExecutor = Qualified.qualified(Lightweight.class, Executor.class);
35+
Qualified<Executor> blockingExecutor = Qualified.qualified(Blocking.class, Executor.class);
36+
37+
return Arrays.asList(
38+
Component.builder(Application.class)
39+
.name(LIBRARY_NAME)
40+
.add(Dependency.required(Context.class))
41+
.factory(
42+
container -> {
43+
Context context = container.get(Context.class);
44+
return (Application) context.getApplicationContext();
45+
})
46+
.build(),
47+
Component.builder(SiteKey.class)
48+
.name(LIBRARY_NAME)
49+
.factory(
50+
container -> new SiteKey(RecaptchaEnterpriseAppCheckProviderFactory.getSiteKey()))
51+
.build(),
52+
Component.builder(RecaptchaEnterpriseAppCheckProvider.class)
53+
.name(LIBRARY_NAME)
54+
.add(Dependency.required(FirebaseApp.class))
55+
.add(Dependency.required(Application.class))
56+
.add(Dependency.required(SiteKey.class))
57+
.add(Dependency.required(liteExecutor))
58+
.add(Dependency.required(blockingExecutor))
59+
.factory(
60+
(container ->
61+
new RecaptchaEnterpriseAppCheckProvider(
62+
container.get(FirebaseApp.class),
63+
container.get(Application.class),
64+
container.get(SiteKey.class),
65+
container.get(liteExecutor),
66+
container.get(blockingExecutor))))
67+
.build(),
68+
LibraryVersionComponent.create(LIBRARY_NAME, BuildConfig.VERSION_NAME));
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.google.firebase.appcheck.recaptchaenterprise;
2+
3+
import androidx.annotation.NonNull;
4+
import com.google.firebase.FirebaseApp;
5+
import com.google.firebase.appcheck.AppCheckProvider;
6+
import com.google.firebase.appcheck.AppCheckProviderFactory;
7+
import com.google.firebase.appcheck.FirebaseAppCheck;
8+
import com.google.firebase.appcheck.recaptchaenterprise.internal.RecaptchaEnterpriseAppCheckProvider;
9+
10+
/**
11+
* Implementation of an {@link AppCheckProviderFactory} that builds <br>
12+
* {@link RecaptchaEnterpriseAppCheckProvider}s. This is the default implementation.
13+
*/
14+
public class RecaptchaEnterpriseAppCheckProviderFactory implements AppCheckProviderFactory {
15+
16+
private static volatile RecaptchaEnterpriseAppCheckProviderFactory instance;
17+
private static String siteKey;
18+
19+
/** Gets an instance of this class for installation into a {@link FirebaseAppCheck} instance. */
20+
@NonNull
21+
public static RecaptchaEnterpriseAppCheckProviderFactory getInstance(@NonNull String siteKey) {
22+
if (instance == null) {
23+
synchronized (RecaptchaEnterpriseAppCheckProviderFactory.class) {
24+
if (instance == null) {
25+
instance = new RecaptchaEnterpriseAppCheckProviderFactory();
26+
RecaptchaEnterpriseAppCheckProviderFactory.siteKey = siteKey;
27+
}
28+
}
29+
}
30+
return instance;
31+
}
32+
33+
@NonNull
34+
public static String getSiteKey() {
35+
return siteKey;
36+
}
37+
38+
@NonNull
39+
@Override
40+
@SuppressWarnings("FirebaseUseExplicitDependencies")
41+
public AppCheckProvider create(@NonNull FirebaseApp firebaseApp) {
42+
return firebaseApp.get(RecaptchaEnterpriseAppCheckProvider.class);
43+
}
44+
}

0 commit comments

Comments
 (0)