Skip to content

Commit 0344327

Browse files
authored
Add initial App Check logic (#669)
* Add initial App Check logic * Add packaging logic * Update app_check.json * Update app_check.json * Update app_check.json * Update app_check.i
1 parent b4c130d commit 0344327

File tree

16 files changed

+649
-4
lines changed

16 files changed

+649
-4
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ option(FIREBASE_INCLUDE_LIBRARY_DEFAULT
3535
option(FIREBASE_INCLUDE_ANALYTICS
3636
"Include the Google Analytics for Firebase library."
3737
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
38+
option(FIREBASE_INCLUDE_APP_CHECK
39+
"Include the Firebase App Check library."
40+
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
3841
option(FIREBASE_INCLUDE_AUTH
3942
"Include the Firebase Authentication library."
4043
${FIREBASE_INCLUDE_LIBRARY_DEFAULT})
@@ -265,6 +268,12 @@ if (FIREBASE_INCLUDE_ANALYTICS)
265268
list(APPEND DOCUMENTATION_ONLY_LIB_NAMES "firebase_analytics_swig")
266269
list(APPEND PROJECT_LIST_HEADER " X(Analytics)")
267270
endif()
271+
if (FIREBASE_INCLUDE_APP_CHECK)
272+
add_subdirectory(app_check)
273+
list(APPEND TARGET_LINK_LIB_NAMES "firebase_app_check" "firebase_app_check_swig")
274+
list(APPEND DOCUMENTATION_ONLY_LIB_NAMES "firebase_app_check_swig")
275+
list(APPEND PROJECT_LIST_HEADER " X(AppCheck)")
276+
endif()
268277
if (FIREBASE_INCLUDE_AUTH)
269278
add_subdirectory(auth)
270279
list(APPEND TARGET_LINK_LIB_NAMES "firebase_auth" "firebase_auth_swig")

app/platform/Unity/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
[assembly: InternalsVisibleTo("Firebase.Analytics")]
3333
[assembly: InternalsVisibleTo("Firebase.App")]
34+
[assembly: InternalsVisibleTo("Firebase.AppCheck")]
3435
[assembly: InternalsVisibleTo("Firebase.Auth")]
3536
[assembly: InternalsVisibleTo("Firebase.Crashlytics")]
3637
[assembly: InternalsVisibleTo("Firebase.Database")]

app/src/swig/app.i

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,10 @@ static firebase::AppOptions* AppOptionsLoadFromJsonConfig(const char* config) {
667667
"Firebase.Analytics.FirebaseAnalytics, Firebase.Analytics",
668668
"analytics"
669669
),
670+
new EnableModuleParams(
671+
"Firebase.AppCheck.FirebaseAppCheck, Firebase.AppCheck",
672+
"app_check"
673+
),
670674
new EnableModuleParams(
671675
"Firebase.Auth.FirebaseAuth, Firebase.Auth",
672676
"auth"

app/src/unity_main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ jint JNI_OnLoad(JavaVM *jvm, void *reserved) {
105105
const char *module_name;
106106
} kJavaClassModuleMap[] = {
107107
{"com/google/firebase/analytics/FirebaseAnalytics", "analytics"},
108+
{"com/google/firebase/appcheck/FirebaseAppCheck", "app_check"},
108109
{"com/google/firebase/auth/FirebaseAuth", "auth"},
109110
{"com/google/firebase/crashlytics/FirebaseCrashlytics", "crashlytics"},
110111
{"com/google/firebase/database/FirebaseDatabase", "database"},

app_check/CMakeLists.txt

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Copyright 2023 Google
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# CMake file for the firebase app check library
16+
17+
include(build_shared)
18+
19+
# Firebase App Check Swig input files
20+
set(firebase_app_check_swig
21+
src/swig/app_check.i
22+
)
23+
24+
# Firebase App Check CSharp files
25+
set(firebase_app_check_src
26+
)
27+
28+
if(NOT FIREBASE_UNI_LIBRARY AND APPLE AND NOT IOS)
29+
set(EXTERNAL_LIB_NAMES
30+
"-framework Foundation"
31+
"-framework Security"
32+
)
33+
else()
34+
set(EXTERNAL_LIB_NAMES)
35+
endif()
36+
37+
firebase_swig_add_library(firebase_app_check_swig
38+
NAMESPACE
39+
Firebase.AppCheck
40+
MODULE
41+
FirebaseCppAppCheck
42+
SOURCES
43+
${firebase_app_check_swig}
44+
DEPENDS
45+
firebase_app_check
46+
SYSTEM_DEPS
47+
${EXTERNAL_LIB_NAMES}
48+
)
49+
50+
unity_pack_documentation_sources(app_check
51+
DOCUMENTATION_SOURCES
52+
${firebase_app_check_src}
53+
${firebase_app_check_swig_gen_src}
54+
)
55+
if (FIREBASE_GENERATE_SWIG_ONLY)
56+
unity_pack_documentation_sources(app_check
57+
DOCUMENTATION_SOURCES
58+
${firebase_app_check_swig_gen_cpp_src}
59+
)
60+
return()
61+
endif()
62+
63+
mono_add_library(firebase_app_check_cs
64+
MODULE
65+
Firebase.AppCheck
66+
SOURCES
67+
${firebase_app_check_src}
68+
${firebase_app_check_swig_gen_src}
69+
REFERENCES
70+
${FIREBASE_PLATFORM_REF}
71+
DEPENDS
72+
firebase_app_check_swig
73+
)
74+
75+
if(FIREBASE_IOS_BUILD)
76+
ios_pack(firebase_lib_app_check libFirebaseCppAppCheck DEPS firebase_app_check firebase_app_check_swig)
77+
else()
78+
build_firebase_shared(
79+
app_check
80+
appcheck
81+
FirebaseCppAppCheck
82+
)
83+
endif()
84+
85+
unity_pack_cs(firebase_app_check_cs)
86+
87+
if (FIREBASE_INCLUDE_UNITY)
88+
generate_dependencies_xml(AppCheck
89+
IOS_DEPS
90+
"Firebase/AppCheck"
91+
ANDROID_DEPS
92+
${FIREBASE_APP_CHECK_ANDROID_DEPS}
93+
ANDROID_SPEC
94+
"appcheck"
95+
)
96+
endif()
97+
98+
set_property(TARGET firebase_app_check_cs
99+
PROPERTY FOLDER
100+
"Firebase ${FIREBASE_PLATFORM_NAME}"
101+
)

app_check/src/swig/app_check.i

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright 2023 Google Inc. All Rights Reserved.
2+
//
3+
// C# bindings for the App Check C++ interface.
4+
5+
%module AppCheckUtil
6+
7+
#ifdef USE_EXPORT_FIX
8+
// Generate a function that we can reference to force linker
9+
// to include the generated swig library symbols correctly
10+
// see export_fix.cc for more details
11+
%include "app/src/export_fix.h"
12+
%{#include "app/src/export_fix.h"%}
13+
#endif
14+
15+
%pragma(csharp) moduleclassmodifiers="internal sealed class"
16+
%feature("flatnested");
17+
18+
%import "app/src/swig/app.i"
19+
%include "app/src/swig/future.i"
20+
%include "app/src/swig/null_check_this.i"
21+
%include "app/src/swig/serial_dispose.i"
22+
23+
// Include required headers for the generated C++ module.
24+
%{
25+
#include "app_check/src/include/firebase/app_check.h"
26+
#include "app_check/src/include/firebase/app_check/app_attest_provider.h"
27+
#include "app_check/src/include/firebase/app_check/debug_provider.h"
28+
#include "app_check/src/include/firebase/app_check/device_check_provider.h"
29+
#include "app_check/src/include/firebase/app_check/play_integrity_provider.h"
30+
%}
31+
32+
// Wrap the Futures used by App Check
33+
%SWIG_FUTURE(Future_AppCheckToken, AppCheckTokenInternal, internal,
34+
firebase::app_check::AppCheckToken, FirebaseException);
35+
36+
// Rename all the generated classes to *Internal, which will
37+
// not be exposed in the public interface, but can be referenced
38+
// from the hand written C# code.
39+
%rename("AppCheckInternal")
40+
firebase::app_check::AppCheck;
41+
%rename("AppCheckTokenInternal")
42+
firebase::app_check::AppCheckToken;
43+
%rename("AppCheckListenerInternal")
44+
firebase::app_check::AppCheckListener;
45+
%rename("AppCheckProviderInternal")
46+
firebase::app_check::AppCheckProvider;
47+
%rename("AppCheckProviderFactoryInternal")
48+
firebase::app_check::AppCheckProviderFactory;
49+
%rename("AppCheckProviderInternal")
50+
firebase::app_check::AppCheckProvider;
51+
// The default Providers
52+
%rename("AppAttestProviderFactoryInternal")
53+
firebase::app_check::AppAttestProviderFactory;
54+
%rename("DebugAppCheckProviderFactoryInternal")
55+
firebase::app_check::DebugAppCheckProviderFactory;
56+
%rename("DeviceCheckProviderFactoryInternal")
57+
firebase::app_check::DeviceCheckProviderFactory;
58+
%rename("PlayIntegrityProviderFactoryInternal")
59+
firebase::app_check::PlayIntegrityProviderFactory;
60+
61+
// Ignore the Error enum, since it will just be done by hand.
62+
%ignore firebase::app_check::AppCheckError;
63+
64+
// Ignore GetToken, which is going to have to be handled differently
65+
%ignore GetToken;
66+
67+
%include "app_check/src/include/firebase/app_check/app_attest_provider.h"
68+
%include "app_check/src/include/firebase/app_check/debug_provider.h"
69+
%include "app_check/src/include/firebase/app_check/device_check_provider.h"
70+
%include "app_check/src/include/firebase/app_check/play_integrity_provider.h"
71+
%include "app_check/src/include/firebase/app_check.h"

cmake/android_dependencies.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ set(FIREBASE_ANALYTICS_ANDROID_DEPS
2424
"com.google.firebase:firebase-analytics:21.2.1"
2525
)
2626

27+
set(FIREBASE_APP_CHECK_ANDROID_DEPS
28+
"com.google.firebase:firebase-appcheck"
29+
"com.google.firebase:firebase-appcheck-debug"
30+
"com.google.firebase:firebase-appcheck-playintegrity"
31+
"com.google.firebase:firebase-analytics:21.2.1"
32+
)
33+
2734
set(FIREBASE_AUTH_ANDROID_DEPS
2835
"com.google.firebase:firebase-auth:21.2.0"
2936
"com.google.firebase:firebase-analytics:21.2.1"

docs/app_check/AppCheckReadme.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Get Started with Firebase App Check
2+
===================================
3+
4+
Thank you for installing the Firebase App Check Unity SDK. App Check
5+
is intended to be used in conjunction with other Firebase products:
6+
7+
* [Cloud Firestore](https://firebase.google.com/products/firestore/)
8+
* [Cloud Functions for Firebase](https://firebase.google.com/products/functions/)
9+
* [Firebase Realtime Database](https://firebase.google.com/products/realtime-database/)
10+
* [Firebase Remote Config](https://firebase.google.com/products/remote-config/)
11+
12+
# Overview
13+
14+
[Firebase App Check](https://firebase.google.com/docs/app-check/)
15+
helps protect your API resources from abuse by preventing unauthorized clients
16+
from accessing your backend resources. It works with both Firebase services,
17+
Google Cloud services, and your own APIs to keep your resources safe.
18+
19+
# Demos
20+
21+
22+
23+
# Links
24+
25+
* [Homepage](https://firebase.google.com/games/)
26+
* [Contact](https://firebase.google.com/support/contact/)
27+
* [Unity Quickstart Samples](https://github.com/firebase/quickstart-unity)
28+
29+
# Discussion
30+
31+
* [Stack overflow](https://stackoverflow.com/questions/tagged/firebase)
32+
* [Slack community](https://firebase-community.slack.com/)
33+
* [Google groups](https://groups.google.com/forum/#!forum/firebase-talk)

proxy/AssemblyInfoApp.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
// Firebase App contains internals that need to be visibly to the other
3333
// Firebase Unity projects, so mark them as friends.
3434
[assembly: InternalsVisibleTo("Firebase.Analytics")]
35+
[assembly: InternalsVisibleTo("Firebase.AppCheck")]
3536
[assembly: InternalsVisibleTo("Firebase.Auth")]
3637
[assembly: InternalsVisibleTo("Firebase.Crash")]
3738
[assembly: InternalsVisibleTo("Firebase.Crashlytics")]

release_build_files/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ unity_pack_file(
3030
PACK_PATH "Firebase/Editor"
3131
)
3232

33+
unity_pack_file(
34+
"${FIREBASE_UNITY_DIR}/docs/app_check/AppCheckReadme.md"
35+
PACK_PATH "Firebase/Editor"
36+
)
37+
3338
unity_pack_file(
3439
"${FIREBASE_UNITY_DIR}/docs/auth/AuthReadme.md"
3540
PACK_PATH "Firebase/Editor"

0 commit comments

Comments
 (0)