@@ -135,25 +135,50 @@ internal enum FunctionsConstants {
135
135
return functions ( app: app, region: FunctionsConstants . defaultRegion, customDomain: customDomain)
136
136
}
137
137
138
- /**
139
- * Creates a reference to the Callable HTTPS trigger with the given name.
140
- * - Parameter name The name of the Callable HTTPS trigger.
141
- */
138
+ /// Creates a reference to the Callable HTTPS trigger with the given name.
139
+ /// - Parameter name: The name of the Callable HTTPS trigger.
140
+ /// - Returns: A reference to a Callable HTTPS trigger.
142
141
@objc ( HTTPSCallableWithName: ) open func httpsCallable( _ name: String ) -> HTTPSCallable {
143
142
return HTTPSCallable ( functions: self , name: name)
144
143
}
145
144
145
+ /// Creates a reference to the Callable HTTPS trigger with the given name and configuration options.
146
+ /// - Parameters:
147
+ /// - name: The name of the Callable HTTPS trigger.
148
+ /// - options: The options with which to customize the Callable HTTPS trigger.
149
+ /// - Returns: A reference to a Callable HTTPS trigger.
150
+ @objc ( HTTPSCallableWithName: options: ) public func httpsCallable( _ name: String ,
151
+ options: HTTPSCallableOptions )
152
+ -> HTTPSCallable {
153
+ return HTTPSCallable ( functions: self , name: name, options: options)
154
+ }
155
+
156
+ /// Creates a reference to the Callable HTTPS trigger with the given name.
157
+ /// - Parameter url: The URL of the Callable HTTPS trigger.
158
+ /// - Returns: A reference to a Callable HTTPS trigger.
146
159
@objc ( HTTPSCallableWithURL: ) open func httpsCallable( _ url: URL ) -> HTTPSCallable {
147
160
return HTTPSCallable ( functions: self , url: url)
148
161
}
149
162
163
+ /// Creates a reference to the Callable HTTPS trigger with the given name and configuration options.
164
+ /// - Parameters:
165
+ /// - url: The URL of the Callable HTTPS trigger.
166
+ /// - options: The options with which to customize the Callable HTTPS trigger.
167
+ /// - Returns: A reference to a Callable HTTPS trigger.
168
+ @objc ( HTTPSCallableWithURL: options: ) public func httpsCallable( _ url: URL ,
169
+ options: HTTPSCallableOptions )
170
+ -> HTTPSCallable {
171
+ return HTTPSCallable ( functions: self , url: url, options: options)
172
+ }
173
+
150
174
/// Creates a reference to the Callable HTTPS trigger with the given name, the type of an `Encodable`
151
175
/// request and the type of a `Decodable` response.
152
- /// - Parameter name: The name of the Callable HTTPS trigger
153
- /// - Parameter requestAs: The type of the `Encodable` entity to use for requests to this `Callable`
154
- /// - Parameter responseAs: The type of the `Decodable` entity to use for responses from this `Callable`
155
- /// - Parameter encoder: The encoder instance to use to run the encoding.
156
- /// - Parameter decoder: The decoder instance to use to run the decoding.
176
+ /// - Parameters:
177
+ /// - name: The name of the Callable HTTPS trigger
178
+ /// - requestAs: The type of the `Encodable` entity to use for requests to this `Callable`
179
+ /// - responseAs: The type of the `Decodable` entity to use for responses from this `Callable`
180
+ /// - encoder: The encoder instance to use to perform encoding.
181
+ /// - decoder: The decoder instance to use to perform decoding.
157
182
/// - Returns: A reference to an HTTPS-callable Cloud Function that can be used to make Cloud Functions invocations.
158
183
open func httpsCallable< Request: Encodable ,
159
184
Response: Decodable > ( _ name: String ,
@@ -164,16 +189,48 @@ internal enum FunctionsConstants {
164
189
decoder: FirebaseDataDecoder = FirebaseDataDecoder (
165
190
) )
166
191
-> Callable < Request , Response > {
167
- return Callable ( callable: httpsCallable ( name) , encoder: encoder, decoder: decoder)
192
+ return Callable (
193
+ callable: httpsCallable ( name) ,
194
+ encoder: encoder,
195
+ decoder: decoder
196
+ )
168
197
}
169
198
170
199
/// Creates a reference to the Callable HTTPS trigger with the given name, the type of an `Encodable`
171
200
/// request and the type of a `Decodable` response.
172
- /// - Parameter url: The url of the Callable HTTPS trigger
173
- /// - Parameter requestAs: The type of the `Encodable` entity to use for requests to this `Callable`
174
- /// - Parameter responseAs: The type of the `Decodable` entity to use for responses from this `Callable`
175
- /// - Parameter encoder: The encoder instance to use to run the encoding.
176
- /// - Parameter decoder: The decoder instance to use to run the decoding.
201
+ /// - Parameters:
202
+ /// - name: The name of the Callable HTTPS trigger
203
+ /// - options: The options with which to customize the Callable HTTPS trigger.
204
+ /// - requestAs: The type of the `Encodable` entity to use for requests to this `Callable`
205
+ /// - responseAs: The type of the `Decodable` entity to use for responses from this `Callable`
206
+ /// - encoder: The encoder instance to use to perform encoding.
207
+ /// - decoder: The decoder instance to use to perform decoding.
208
+ /// - Returns: A reference to an HTTPS-callable Cloud Function that can be used to make Cloud Functions invocations.
209
+ open func httpsCallable< Request: Encodable ,
210
+ Response: Decodable > ( _ name: String ,
211
+ options: HTTPSCallableOptions ,
212
+ requestAs: Request . Type = Request . self,
213
+ responseAs: Response . Type = Response . self,
214
+ encoder: FirebaseDataEncoder = FirebaseDataEncoder (
215
+ ) ,
216
+ decoder: FirebaseDataDecoder = FirebaseDataDecoder (
217
+ ) )
218
+ -> Callable < Request , Response > {
219
+ return Callable (
220
+ callable: httpsCallable ( name, options: options) ,
221
+ encoder: encoder,
222
+ decoder: decoder
223
+ )
224
+ }
225
+
226
+ /// Creates a reference to the Callable HTTPS trigger with the given name, the type of an `Encodable`
227
+ /// request and the type of a `Decodable` response.
228
+ /// - Parameters:
229
+ /// - url: The url of the Callable HTTPS trigger
230
+ /// - requestAs: The type of the `Encodable` entity to use for requests to this `Callable`
231
+ /// - responseAs: The type of the `Decodable` entity to use for responses from this `Callable`
232
+ /// - encoder: The encoder instance to use to perform encoding.
233
+ /// - decoder: The decoder instance to use to perform decoding.
177
234
/// - Returns: A reference to an HTTPS-callable Cloud Function that can be used to make Cloud Functions invocations.
178
235
open func httpsCallable< Request: Encodable ,
179
236
Response: Decodable > ( _ url: URL ,
@@ -184,7 +241,38 @@ internal enum FunctionsConstants {
184
241
decoder: FirebaseDataDecoder = FirebaseDataDecoder (
185
242
) )
186
243
-> Callable < Request , Response > {
187
- return Callable ( callable: httpsCallable ( url) , encoder: encoder, decoder: decoder)
244
+ return Callable (
245
+ callable: httpsCallable ( url) ,
246
+ encoder: encoder,
247
+ decoder: decoder
248
+ )
249
+ }
250
+
251
+ /// Creates a reference to the Callable HTTPS trigger with the given name, the type of an `Encodable`
252
+ /// request and the type of a `Decodable` response.
253
+ /// - Parameters:
254
+ /// - url: The url of the Callable HTTPS trigger
255
+ /// - options: The options with which to customize the Callable HTTPS trigger.
256
+ /// - requestAs: The type of the `Encodable` entity to use for requests to this `Callable`
257
+ /// - responseAs: The type of the `Decodable` entity to use for responses from this `Callable`
258
+ /// - encoder: The encoder instance to use to perform encoding.
259
+ /// - decoder: The decoder instance to use to perform decoding.
260
+ /// - Returns: A reference to an HTTPS-callable Cloud Function that can be used to make Cloud Functions invocations.
261
+ open func httpsCallable< Request: Encodable ,
262
+ Response: Decodable > ( _ url: URL ,
263
+ options: HTTPSCallableOptions ,
264
+ requestAs: Request . Type = Request . self,
265
+ responseAs: Response . Type = Response . self,
266
+ encoder: FirebaseDataEncoder = FirebaseDataEncoder (
267
+ ) ,
268
+ decoder: FirebaseDataDecoder = FirebaseDataDecoder (
269
+ ) )
270
+ -> Callable < Request , Response > {
271
+ return Callable (
272
+ callable: httpsCallable ( url, options: options) ,
273
+ encoder: encoder,
274
+ decoder: decoder
275
+ )
188
276
}
189
277
190
278
/**
@@ -273,10 +361,11 @@ internal enum FunctionsConstants {
273
361
274
362
internal func callFunction( name: String ,
275
363
withObject data: Any ? ,
364
+ options: HTTPSCallableOptions ? ,
276
365
timeout: TimeInterval ,
277
366
completion: @escaping ( ( Result < HTTPSCallableResult , Error > ) -> Void ) ) {
278
367
// Get context first.
279
- contextProvider. getContext { context, error in
368
+ contextProvider. getContext ( options : options ) { context, error in
280
369
// Note: context is always non-nil since some checks could succeed, we're only failing if
281
370
// there's an error.
282
371
if let error = error {
@@ -285,6 +374,7 @@ internal enum FunctionsConstants {
285
374
let url = self . urlWithName ( name)
286
375
self . callFunction ( url: URL ( string: url) !,
287
376
withObject: data,
377
+ options: options,
288
378
timeout: timeout,
289
379
context: context,
290
380
completion: completion)
@@ -294,17 +384,19 @@ internal enum FunctionsConstants {
294
384
295
385
internal func callFunction( url: URL ,
296
386
withObject data: Any ? ,
387
+ options: HTTPSCallableOptions ? ,
297
388
timeout: TimeInterval ,
298
389
completion: @escaping ( ( Result < HTTPSCallableResult , Error > ) -> Void ) ) {
299
390
// Get context first.
300
- contextProvider. getContext { context, error in
391
+ contextProvider. getContext ( options : options ) { context, error in
301
392
// Note: context is always non-nil since some checks could succeed, we're only failing if
302
393
// there's an error.
303
394
if let error = error {
304
395
completion ( . failure( error) )
305
396
} else {
306
397
self . callFunction ( url: url,
307
398
withObject: data,
399
+ options: options,
308
400
timeout: timeout,
309
401
context: context,
310
402
completion: completion)
@@ -314,6 +406,7 @@ internal enum FunctionsConstants {
314
406
315
407
private func callFunction( url: URL ,
316
408
withObject data: Any ? ,
409
+ options: HTTPSCallableOptions ? ,
317
410
timeout: TimeInterval ,
318
411
context: FunctionsContext ,
319
412
completion: @escaping ( ( Result < HTTPSCallableResult , Error > ) -> Void ) ) {
@@ -353,8 +446,18 @@ internal enum FunctionsConstants {
353
446
fetcher. setRequestValue ( fcmToken, forHTTPHeaderField: Constants . fcmTokenHeader)
354
447
}
355
448
356
- if let appCheckToken = context. appCheckToken {
357
- fetcher. setRequestValue ( appCheckToken, forHTTPHeaderField: Constants . appCheckTokenHeader)
449
+ if options? . requireLimitedUseAppCheckTokens == true {
450
+ if let appCheckToken = context. limitedUseAppCheckToken {
451
+ fetcher. setRequestValue (
452
+ appCheckToken,
453
+ forHTTPHeaderField: Constants . appCheckTokenHeader
454
+ )
455
+ }
456
+ } else if let appCheckToken = context. appCheckToken {
457
+ fetcher. setRequestValue (
458
+ appCheckToken,
459
+ forHTTPHeaderField: Constants . appCheckTokenHeader
460
+ )
358
461
}
359
462
360
463
// Override normal security rules if this is a local test.
0 commit comments