Skip to content

Commit 477d6ea

Browse files
committed
[Vertex AI] Add AppCheck, Auth and Storage frameworks to sample (#12928)
1 parent 7cd652b commit 477d6ea

File tree

2 files changed

+61
-13
lines changed

2 files changed

+61
-13
lines changed

FirebaseVertexAI/Sample/VertexAISample.xcodeproj/project.pbxproj

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
868A33682BB476FA00304BB1 /* FirebaseVertexAI-Preview in Frameworks */ = {isa = PBXBuildFile; productRef = 868A33672BB476FA00304BB1 /* FirebaseVertexAI-Preview */; };
1110
869200B32B879C4F00482873 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 869200B22B879C4F00482873 /* GoogleService-Info.plist */; };
1211
86C1F4832BC726150026816F /* FunctionCallingScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C1F47E2BC726150026816F /* FunctionCallingScreen.swift */; };
1312
86C1F4842BC726150026816F /* FunctionCallingViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86C1F4802BC726150026816F /* FunctionCallingViewModel.swift */; };
13+
86D9CA8B2BED3EE1007D939E /* FirebaseAppCheck in Frameworks */ = {isa = PBXBuildFile; productRef = 86D9CA8A2BED3EE1007D939E /* FirebaseAppCheck */; };
14+
86D9CA8F2BED3EE1007D939E /* FirebaseAuth in Frameworks */ = {isa = PBXBuildFile; productRef = 86D9CA8E2BED3EE1007D939E /* FirebaseAuth */; };
15+
86D9CAB52BED3EE1007D939E /* FirebaseStorage in Frameworks */ = {isa = PBXBuildFile; productRef = 86D9CAB42BED3EE1007D939E /* FirebaseStorage */; };
16+
86D9CAB92BED3EE1007D939E /* FirebaseVertexAI-Preview in Frameworks */ = {isa = PBXBuildFile; productRef = 86D9CAB82BED3EE1007D939E /* FirebaseVertexAI-Preview */; };
1417
88263BF02B239C09008AB09B /* ErrorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88263BEE2B239BFE008AB09B /* ErrorView.swift */; };
1518
88263BF12B239C11008AB09B /* ErrorDetailsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 889873842B208563005B4896 /* ErrorDetailsView.swift */; };
1619
8848C8332B0D04BC007B434F /* VertexAISampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8848C8322B0D04BC007B434F /* VertexAISampleApp.swift */; };
@@ -64,9 +67,12 @@
6467
isa = PBXFrameworksBuildPhase;
6568
buildActionMask = 2147483647;
6669
files = (
67-
868A33682BB476FA00304BB1 /* FirebaseVertexAI-Preview in Frameworks */,
6870
886F95D82B17BA420036F07A /* MarkdownUI in Frameworks */,
71+
86D9CAB52BED3EE1007D939E /* FirebaseStorage in Frameworks */,
72+
86D9CA8F2BED3EE1007D939E /* FirebaseAuth in Frameworks */,
73+
86D9CA8B2BED3EE1007D939E /* FirebaseAppCheck in Frameworks */,
6974
886F95E32B17D6630036F07A /* GenerativeAIUIComponents in Frameworks */,
75+
86D9CAB92BED3EE1007D939E /* FirebaseVertexAI-Preview in Frameworks */,
7076
);
7177
runOnlyForDeploymentPostprocessing = 0;
7278
};
@@ -292,7 +298,10 @@
292298
packageProductDependencies = (
293299
886F95D72B17BA420036F07A /* MarkdownUI */,
294300
886F95E22B17D6630036F07A /* GenerativeAIUIComponents */,
295-
868A33672BB476FA00304BB1 /* FirebaseVertexAI-Preview */,
301+
86D9CA8A2BED3EE1007D939E /* FirebaseAppCheck */,
302+
86D9CA8E2BED3EE1007D939E /* FirebaseAuth */,
303+
86D9CAB42BED3EE1007D939E /* FirebaseStorage */,
304+
86D9CAB82BED3EE1007D939E /* FirebaseVertexAI-Preview */,
296305
);
297306
productName = GenerativeAISample;
298307
productReference = 8848C82F2B0D04BC007B434F /* VertexAISample.app */;
@@ -325,7 +334,7 @@
325334
packageReferences = (
326335
88209C212B0FBDF700F64795 /* XCRemoteSwiftPackageReference "swift-markdown-ui" */,
327336
DEA09AC32B1FCE22001962D9 /* XCRemoteSwiftPackageReference "NetworkImage" */,
328-
868A33642BB476FA00304BB1 /* XCLocalSwiftPackageReference "../.." */,
337+
86D9CA892BED3EE1007D939E /* XCLocalSwiftPackageReference "../.." */,
329338
);
330339
productRefGroup = 8848C8302B0D04BC007B434F /* Products */;
331340
projectDirPath = "";
@@ -578,7 +587,7 @@
578587
/* End XCConfigurationList section */
579588

580589
/* Begin XCLocalSwiftPackageReference section */
581-
868A33642BB476FA00304BB1 /* XCLocalSwiftPackageReference "../.." */ = {
590+
86D9CA892BED3EE1007D939E /* XCLocalSwiftPackageReference "../.." */ = {
582591
isa = XCLocalSwiftPackageReference;
583592
relativePath = ../..;
584593
};
@@ -604,7 +613,19 @@
604613
/* End XCRemoteSwiftPackageReference section */
605614

606615
/* Begin XCSwiftPackageProductDependency section */
607-
868A33672BB476FA00304BB1 /* FirebaseVertexAI-Preview */ = {
616+
86D9CA8A2BED3EE1007D939E /* FirebaseAppCheck */ = {
617+
isa = XCSwiftPackageProductDependency;
618+
productName = FirebaseAppCheck;
619+
};
620+
86D9CA8E2BED3EE1007D939E /* FirebaseAuth */ = {
621+
isa = XCSwiftPackageProductDependency;
622+
productName = FirebaseAuth;
623+
};
624+
86D9CAB42BED3EE1007D939E /* FirebaseStorage */ = {
625+
isa = XCSwiftPackageProductDependency;
626+
productName = FirebaseStorage;
627+
};
628+
86D9CAB82BED3EE1007D939E /* FirebaseVertexAI-Preview */ = {
608629
isa = XCSwiftPackageProductDependency;
609630
productName = "FirebaseVertexAI-Preview";
610631
};

FirebaseVertexAI/Sample/VertexAISample/VertexAISampleApp.swift

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,56 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import FirebaseAppCheck
1516
import FirebaseCore
1617
import SwiftUI
1718

18-
@main
19-
struct VertexAISampleApp: App {
20-
init() {
19+
class AppDelegate: NSObject, UIApplicationDelegate {
20+
func application(_ application: UIApplication,
21+
didFinishLaunchingWithOptions launchOptions: [UIApplication
22+
.LaunchOptionsKey: Any]? = nil) -> Bool {
2123
// Recommendation: Protect your Vertex AI API resources from abuse by preventing unauthorized
2224
// clients using App Check; see https://firebase.google.com/docs/app-check#get_started.
25+
AppCheck.setAppCheckProviderFactory(AppCheckNotConfiguredFactory())
2326

2427
FirebaseApp.configure()
2528

2629
if let firebaseApp = FirebaseApp.app(), firebaseApp.options.projectID == "mockproject-1234" {
2730
guard let bundleID = Bundle.main.bundleIdentifier else { fatalError() }
28-
fatalError("You must create and/or download a valid `GoogleService-Info.plist` file for"
29-
+ " \(bundleID) from https://console.firebase.google.com to run this sample. Replace the"
30-
+ " existing `GoogleService-Info.plist` file in the `FirebaseVertexAI/Sample` directory"
31-
+ " with this new file.")
31+
fatalError("""
32+
You must create and/or download a valid `GoogleService-Info.plist` file for \(bundleID) from \
33+
https://console.firebase.google.com to run this sample. Replace the existing \
34+
`GoogleService-Info.plist` file in the `FirebaseVertexAI/Sample` directory with this new file.
35+
""")
3236
}
37+
38+
return true
3339
}
40+
}
41+
42+
@main
43+
struct VertexAISampleApp: App {
44+
@UIApplicationDelegateAdaptor var appDelegate: AppDelegate
3445

3546
var body: some Scene {
3647
WindowGroup {
3748
ContentView()
3849
}
3950
}
4051
}
52+
53+
/// Placeholder App Check provider factory that returns a simple ``AppCheckNotConfigured`` error.
54+
private class AppCheckNotConfiguredFactory: NSObject, AppCheckProviderFactory {
55+
private class AppCheckNotConfiguredProvider: NSObject, AppCheckProvider {
56+
func getToken() async throws -> AppCheckToken {
57+
throw AppCheckNotConfigured()
58+
}
59+
}
60+
61+
func createProvider(with app: FirebaseApp) -> (any AppCheckProvider)? {
62+
return AppCheckNotConfiguredProvider()
63+
}
64+
}
65+
66+
/// Error indicating that App Check is not configured in the sample app.
67+
struct AppCheckNotConfigured: Error {}

0 commit comments

Comments
 (0)