|
|
@@ -135,25 +135,50 @@ internal enum FunctionsConstants {
|
|
|
return functions(app: app, region: FunctionsConstants.defaultRegion, customDomain: customDomain)
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Creates a reference to the Callable HTTPS trigger with the given name.
|
|
|
- * - Parameter name The name of the Callable HTTPS trigger.
|
|
|
- */
|
|
|
+ /// Creates a reference to the Callable HTTPS trigger with the given name.
|
|
|
+ /// - Parameter name: The name of the Callable HTTPS trigger.
|
|
|
+ /// - Returns: A reference to a Callable HTTPS trigger.
|
|
|
@objc(HTTPSCallableWithName:) open func httpsCallable(_ name: String) -> HTTPSCallable {
|
|
|
return HTTPSCallable(functions: self, name: name)
|
|
|
}
|
|
|
|
|
|
+ /// Creates a reference to the Callable HTTPS trigger with the given name and configuration options.
|
|
|
+ /// - Parameters:
|
|
|
+ /// - name: The name of the Callable HTTPS trigger.
|
|
|
+ /// - options: The options with which to customize the Callable HTTPS trigger.
|
|
|
+ /// - Returns: A reference to a Callable HTTPS trigger.
|
|
|
+ @objc(HTTPSCallableWithName:options:) public func httpsCallable(_ name: String,
|
|
|
+ options: HTTPSCallableOptions)
|
|
|
+ -> HTTPSCallable {
|
|
|
+ return HTTPSCallable(functions: self, name: name, options: options)
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Creates a reference to the Callable HTTPS trigger with the given name.
|
|
|
+ /// - Parameter url: The URL of the Callable HTTPS trigger.
|
|
|
+ /// - Returns: A reference to a Callable HTTPS trigger.
|
|
|
@objc(HTTPSCallableWithURL:) open func httpsCallable(_ url: URL) -> HTTPSCallable {
|
|
|
return HTTPSCallable(functions: self, url: url)
|
|
|
}
|
|
|
|
|
|
+ /// Creates a reference to the Callable HTTPS trigger with the given name and configuration options.
|
|
|
+ /// - Parameters:
|
|
|
+ /// - url: The URL of the Callable HTTPS trigger.
|
|
|
+ /// - options: The options with which to customize the Callable HTTPS trigger.
|
|
|
+ /// - Returns: A reference to a Callable HTTPS trigger.
|
|
|
+ @objc(HTTPSCallableWithURL:options:) public func httpsCallable(_ url: URL,
|
|
|
+ options: HTTPSCallableOptions)
|
|
|
+ -> HTTPSCallable {
|
|
|
+ return HTTPSCallable(functions: self, url: url, options: options)
|
|
|
+ }
|
|
|
+
|
|
|
/// Creates a reference to the Callable HTTPS trigger with the given name, the type of an `Encodable`
|
|
|
/// request and the type of a `Decodable` response.
|
|
|
- /// - Parameter name: The name of the Callable HTTPS trigger
|
|
|
- /// - Parameter requestAs: The type of the `Encodable` entity to use for requests to this `Callable`
|
|
|
- /// - Parameter responseAs: The type of the `Decodable` entity to use for responses from this `Callable`
|
|
|
- /// - Parameter encoder: The encoder instance to use to run the encoding.
|
|
|
- /// - Parameter decoder: The decoder instance to use to run the decoding.
|
|
|
+ /// - Parameters:
|
|
|
+ /// - name: The name of the Callable HTTPS trigger
|
|
|
+ /// - requestAs: The type of the `Encodable` entity to use for requests to this `Callable`
|
|
|
+ /// - responseAs: The type of the `Decodable` entity to use for responses from this `Callable`
|
|
|
+ /// - encoder: The encoder instance to use to perform encoding.
|
|
|
+ /// - decoder: The decoder instance to use to perform decoding.
|
|
|
/// - Returns: A reference to an HTTPS-callable Cloud Function that can be used to make Cloud Functions invocations.
|
|
|
open func httpsCallable<Request: Encodable,
|
|
|
Response: Decodable>(_ name: String,
|
|
|
@@ -164,16 +189,48 @@ internal enum FunctionsConstants {
|
|
|
decoder: FirebaseDataDecoder = FirebaseDataDecoder(
|
|
|
))
|
|
|
-> Callable<Request, Response> {
|
|
|
- return Callable(callable: httpsCallable(name), encoder: encoder, decoder: decoder)
|
|
|
+ return Callable(
|
|
|
+ callable: httpsCallable(name),
|
|
|
+ encoder: encoder,
|
|
|
+ decoder: decoder
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
/// Creates a reference to the Callable HTTPS trigger with the given name, the type of an `Encodable`
|
|
|
/// request and the type of a `Decodable` response.
|
|
|
- /// - Parameter url: The url of the Callable HTTPS trigger
|
|
|
- /// - Parameter requestAs: The type of the `Encodable` entity to use for requests to this `Callable`
|
|
|
- /// - Parameter responseAs: The type of the `Decodable` entity to use for responses from this `Callable`
|
|
|
- /// - Parameter encoder: The encoder instance to use to run the encoding.
|
|
|
- /// - Parameter decoder: The decoder instance to use to run the decoding.
|
|
|
+ /// - Parameters:
|
|
|
+ /// - name: The name of the Callable HTTPS trigger
|
|
|
+ /// - options: The options with which to customize the Callable HTTPS trigger.
|
|
|
+ /// - requestAs: The type of the `Encodable` entity to use for requests to this `Callable`
|
|
|
+ /// - responseAs: The type of the `Decodable` entity to use for responses from this `Callable`
|
|
|
+ /// - encoder: The encoder instance to use to perform encoding.
|
|
|
+ /// - decoder: The decoder instance to use to perform decoding.
|
|
|
+ /// - Returns: A reference to an HTTPS-callable Cloud Function that can be used to make Cloud Functions invocations.
|
|
|
+ open func httpsCallable<Request: Encodable,
|
|
|
+ Response: Decodable>(_ name: String,
|
|
|
+ options: HTTPSCallableOptions,
|
|
|
+ requestAs: Request.Type = Request.self,
|
|
|
+ responseAs: Response.Type = Response.self,
|
|
|
+ encoder: FirebaseDataEncoder = FirebaseDataEncoder(
|
|
|
+ ),
|
|
|
+ decoder: FirebaseDataDecoder = FirebaseDataDecoder(
|
|
|
+ ))
|
|
|
+ -> Callable<Request, Response> {
|
|
|
+ return Callable(
|
|
|
+ callable: httpsCallable(name, options: options),
|
|
|
+ encoder: encoder,
|
|
|
+ decoder: decoder
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Creates a reference to the Callable HTTPS trigger with the given name, the type of an `Encodable`
|
|
|
+ /// request and the type of a `Decodable` response.
|
|
|
+ /// - Parameters:
|
|
|
+ /// - url: The url of the Callable HTTPS trigger
|
|
|
+ /// - requestAs: The type of the `Encodable` entity to use for requests to this `Callable`
|
|
|
+ /// - responseAs: The type of the `Decodable` entity to use for responses from this `Callable`
|
|
|
+ /// - encoder: The encoder instance to use to perform encoding.
|
|
|
+ /// - decoder: The decoder instance to use to perform decoding.
|
|
|
/// - Returns: A reference to an HTTPS-callable Cloud Function that can be used to make Cloud Functions invocations.
|
|
|
open func httpsCallable<Request: Encodable,
|
|
|
Response: Decodable>(_ url: URL,
|
|
|
@@ -184,7 +241,38 @@ internal enum FunctionsConstants {
|
|
|
decoder: FirebaseDataDecoder = FirebaseDataDecoder(
|
|
|
))
|
|
|
-> Callable<Request, Response> {
|
|
|
- return Callable(callable: httpsCallable(url), encoder: encoder, decoder: decoder)
|
|
|
+ return Callable(
|
|
|
+ callable: httpsCallable(url),
|
|
|
+ encoder: encoder,
|
|
|
+ decoder: decoder
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Creates a reference to the Callable HTTPS trigger with the given name, the type of an `Encodable`
|
|
|
+ /// request and the type of a `Decodable` response.
|
|
|
+ /// - Parameters:
|
|
|
+ /// - url: The url of the Callable HTTPS trigger
|
|
|
+ /// - options: The options with which to customize the Callable HTTPS trigger.
|
|
|
+ /// - requestAs: The type of the `Encodable` entity to use for requests to this `Callable`
|
|
|
+ /// - responseAs: The type of the `Decodable` entity to use for responses from this `Callable`
|
|
|
+ /// - encoder: The encoder instance to use to perform encoding.
|
|
|
+ /// - decoder: The decoder instance to use to perform decoding.
|
|
|
+ /// - Returns: A reference to an HTTPS-callable Cloud Function that can be used to make Cloud Functions invocations.
|
|
|
+ open func httpsCallable<Request: Encodable,
|
|
|
+ Response: Decodable>(_ url: URL,
|
|
|
+ options: HTTPSCallableOptions,
|
|
|
+ requestAs: Request.Type = Request.self,
|
|
|
+ responseAs: Response.Type = Response.self,
|
|
|
+ encoder: FirebaseDataEncoder = FirebaseDataEncoder(
|
|
|
+ ),
|
|
|
+ decoder: FirebaseDataDecoder = FirebaseDataDecoder(
|
|
|
+ ))
|
|
|
+ -> Callable<Request, Response> {
|
|
|
+ return Callable(
|
|
|
+ callable: httpsCallable(url, options: options),
|
|
|
+ encoder: encoder,
|
|
|
+ decoder: decoder
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -273,10 +361,11 @@ internal enum FunctionsConstants {
|
|
|
|
|
|
internal func callFunction(name: String,
|
|
|
withObject data: Any?,
|
|
|
+ options: HTTPSCallableOptions?,
|
|
|
timeout: TimeInterval,
|
|
|
completion: @escaping ((Result<HTTPSCallableResult, Error>) -> Void)) {
|
|
|
// Get context first.
|
|
|
- contextProvider.getContext { context, error in
|
|
|
+ contextProvider.getContext(options: options) { context, error in
|
|
|
// Note: context is always non-nil since some checks could succeed, we're only failing if
|
|
|
// there's an error.
|
|
|
if let error = error {
|
|
|
@@ -285,6 +374,7 @@ internal enum FunctionsConstants {
|
|
|
let url = self.urlWithName(name)
|
|
|
self.callFunction(url: URL(string: url)!,
|
|
|
withObject: data,
|
|
|
+ options: options,
|
|
|
timeout: timeout,
|
|
|
context: context,
|
|
|
completion: completion)
|
|
|
@@ -294,10 +384,11 @@ internal enum FunctionsConstants {
|
|
|
|
|
|
internal func callFunction(url: URL,
|
|
|
withObject data: Any?,
|
|
|
+ options: HTTPSCallableOptions?,
|
|
|
timeout: TimeInterval,
|
|
|
completion: @escaping ((Result<HTTPSCallableResult, Error>) -> Void)) {
|
|
|
// Get context first.
|
|
|
- contextProvider.getContext { context, error in
|
|
|
+ contextProvider.getContext(options: options) { context, error in
|
|
|
// Note: context is always non-nil since some checks could succeed, we're only failing if
|
|
|
// there's an error.
|
|
|
if let error = error {
|
|
|
@@ -305,6 +396,7 @@ internal enum FunctionsConstants {
|
|
|
} else {
|
|
|
self.callFunction(url: url,
|
|
|
withObject: data,
|
|
|
+ options: options,
|
|
|
timeout: timeout,
|
|
|
context: context,
|
|
|
completion: completion)
|
|
|
@@ -314,6 +406,7 @@ internal enum FunctionsConstants {
|
|
|
|
|
|
private func callFunction(url: URL,
|
|
|
withObject data: Any?,
|
|
|
+ options: HTTPSCallableOptions?,
|
|
|
timeout: TimeInterval,
|
|
|
context: FunctionsContext,
|
|
|
completion: @escaping ((Result<HTTPSCallableResult, Error>) -> Void)) {
|
|
|
@@ -353,8 +446,18 @@ internal enum FunctionsConstants {
|
|
|
fetcher.setRequestValue(fcmToken, forHTTPHeaderField: Constants.fcmTokenHeader)
|
|
|
}
|
|
|
|
|
|
- if let appCheckToken = context.appCheckToken {
|
|
|
- fetcher.setRequestValue(appCheckToken, forHTTPHeaderField: Constants.appCheckTokenHeader)
|
|
|
+ if options?.requireLimitedUseAppCheckTokens == true {
|
|
|
+ if let appCheckToken = context.limitedUseAppCheckToken {
|
|
|
+ fetcher.setRequestValue(
|
|
|
+ appCheckToken,
|
|
|
+ forHTTPHeaderField: Constants.appCheckTokenHeader
|
|
|
+ )
|
|
|
+ }
|
|
|
+ } else if let appCheckToken = context.appCheckToken {
|
|
|
+ fetcher.setRequestValue(
|
|
|
+ appCheckToken,
|
|
|
+ forHTTPHeaderField: Constants.appCheckTokenHeader
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
// Override normal security rules if this is a local test.
|