@@ -35,15 +35,33 @@ public final class FirebaseAI: Sendable {
35
35
/// - config: Configuration options for the Firebase AI SDK that propogate across all models
36
36
/// created. Uses default options when not specified, see the ``FirebaseAI.Config``
37
37
/// documentation for more information.
38
+ /// - useLimitedUseAppCheckTokens: When sending tokens to the backend, this option enables
39
+ /// the usage of App Check's limited-use tokens instead of the standard cached tokens.
40
+ ///
41
+ /// A new limited-use tokens will be generated for each request; providing a smaller attack
42
+ /// surface for malicious parties to hijack tokens. When used alongside replay protection,
43
+ /// limited-use tokens are also _consumed_ after each request, ensuring they can't be used
44
+ /// again.
45
+ ///
46
+ /// _This flag is set to `false` by default._
47
+ ///
48
+ /// > Important: Replay protection is not currently supported for the FirebaseAI backend.
49
+ /// > While this feature is being developed, you can still migrate to using
50
+ /// > limited-use tokens. Because limited-use tokens are backwards compatible, you can still
51
+ /// > use them without replay protection. Due to their shorter TTL over standard App Check
52
+ /// > tokens, they still provide a security benefit.
53
+ /// >
54
+ /// > Migrating to limited-use tokens sooner minimizes disruption when support for replay
55
+ /// > protection is added.
38
56
/// - Returns: A `FirebaseAI` instance, configured with the custom `FirebaseApp`.
39
57
public static func firebaseAI( app: FirebaseApp ? = nil ,
40
58
backend: Backend = . googleAI( ) ,
41
- config : FirebaseAI . Config = . config ( ) ) -> FirebaseAI {
59
+ useLimitedUseAppCheckTokens : Bool = false ) -> FirebaseAI {
42
60
let instance = createInstance (
43
61
app: app,
44
62
location: backend. location,
45
63
apiConfig: backend. apiConfig,
46
- aiConfig : config
64
+ useLimitedUseAppCheckTokens : useLimitedUseAppCheckTokens
47
65
)
48
66
// Verify that the `FirebaseAI` instance is always configured with the production endpoint since
49
67
// this is the public API surface for creating an instance.
@@ -96,7 +114,7 @@ public final class FirebaseAI: Sendable {
96
114
toolConfig: toolConfig,
97
115
systemInstruction: systemInstruction,
98
116
requestOptions: requestOptions,
99
- aiConfig : aiConfig
117
+ useLimitedUseAppCheckTokens : useLimitedUseAppCheckTokens
100
118
)
101
119
}
102
120
@@ -133,37 +151,22 @@ public final class FirebaseAI: Sendable {
133
151
generationConfig: generationConfig,
134
152
safetySettings: safetySettings,
135
153
requestOptions: requestOptions,
136
- aiConfig : aiConfig
154
+ useLimitedUseAppCheckTokens : useLimitedUseAppCheckTokens
137
155
)
138
156
}
139
157
140
158
/// Class to enable FirebaseAI to register via the Objective-C based Firebase component system
141
159
/// to include FirebaseAI in the userAgent.
142
160
@objc ( FIRVertexAIComponent) class FirebaseVertexAIComponent : NSObject { }
143
161
144
- /// Configuration options for ``FirebaseAI``, which persists across all models.
145
- @available ( iOS 15 . 0 , macOS 12 . 0 , macCatalyst 15 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
146
- public struct Config : Sendable , Hashable , Equatable {
147
- /// Options for App Check specific behavior within a ``FirebaseAI`` instance.
148
- let appCheck : AppCheckOptions
149
-
150
- /// Creates a new ``FirebaseAI.Config`` value.
151
- ///
152
- /// - Parameters:
153
- /// - appCheck: Optionally configure certain behavior with how App Check is used.
154
- public static func config( appCheck: AppCheckOptions = AppCheckOptions ( ) ) -> Config {
155
- Config ( appCheck: appCheck)
156
- }
157
- }
158
-
159
162
// MARK: - Private
160
163
161
164
/// Firebase data relevant to Firebase AI.
162
165
let firebaseInfo : FirebaseInfo
163
166
164
167
let apiConfig : APIConfig
165
168
166
- let aiConfig : FirebaseAI . Config
169
+ let useLimitedUseAppCheckTokens : Bool
167
170
168
171
/// A map of active `FirebaseAI` instances keyed by the `FirebaseApp` name and the `location`,
169
172
/// in the format `appName:location`.
@@ -180,7 +183,7 @@ public final class FirebaseAI: Sendable {
180
183
)
181
184
182
185
static func createInstance( app: FirebaseApp ? , location: String ? ,
183
- apiConfig: APIConfig , aiConfig : FirebaseAI . Config ) -> FirebaseAI {
186
+ apiConfig: APIConfig , useLimitedUseAppCheckTokens : Bool ) -> FirebaseAI {
184
187
guard let app = app ?? FirebaseApp . app ( ) else {
185
188
fatalError ( " No instance of the default Firebase app was found. " )
186
189
}
@@ -194,7 +197,7 @@ public final class FirebaseAI: Sendable {
194
197
appName: app. name,
195
198
location: location,
196
199
apiConfig: apiConfig,
197
- aiConfig : aiConfig
200
+ useLimitedUseAppCheckTokens : useLimitedUseAppCheckTokens
198
201
)
199
202
if let instance = instances [ instanceKey] {
200
203
return instance
@@ -203,13 +206,13 @@ public final class FirebaseAI: Sendable {
203
206
app: app,
204
207
location: location,
205
208
apiConfig: apiConfig,
206
- aiConfig : aiConfig
209
+ useLimitedUseAppCheckTokens : useLimitedUseAppCheckTokens
207
210
)
208
211
instances [ instanceKey] = newInstance
209
212
return newInstance
210
213
}
211
214
212
- init ( app: FirebaseApp , location: String ? , apiConfig: APIConfig , aiConfig : FirebaseAI . Config ) {
215
+ init ( app: FirebaseApp , location: String ? , apiConfig: APIConfig , useLimitedUseAppCheckTokens : Bool ) {
213
216
guard let projectID = app. options. projectID else {
214
217
fatalError ( " The Firebase app named \" \( app. name) \" has no project ID in its configuration. " )
215
218
}
@@ -229,7 +232,7 @@ public final class FirebaseAI: Sendable {
229
232
)
230
233
self . apiConfig = apiConfig
231
234
self . location = location
232
- self . aiConfig = aiConfig
235
+ self . useLimitedUseAppCheckTokens = useLimitedUseAppCheckTokens
233
236
}
234
237
235
238
func modelResourceName( modelName: String ) -> String {
@@ -284,6 +287,6 @@ public final class FirebaseAI: Sendable {
284
287
let appName : String
285
288
let location : String ?
286
289
let apiConfig : APIConfig
287
- let aiConfig : FirebaseAI . Config
290
+ let useLimitedUseAppCheckTokens : Bool
288
291
}
289
292
}
0 commit comments