AuthRPCRequest.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2023 Google LLC
  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. import Foundation
  15. /// The generic interface for an RPC request needed by AuthBackend.
  16. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  17. protocol AuthRPCRequest {
  18. associatedtype Response: AuthRPCResponse
  19. /// Gets the request's full URL.
  20. func requestURL() -> URL
  21. /// Returns whether the request contains a post body or not. Requests without a post body are
  22. /// GET requests. A default implementation returns `true`.
  23. var containsPostBody: Bool { get }
  24. /// Creates unencoded HTTP body representing the request.
  25. /// - Throws: Any error which occurred constructing the request.
  26. /// - Returns: The HTTP body data representing the request before any encoding.
  27. func unencodedHTTPRequestBody() throws -> [String: AnyHashable]
  28. /// The request configuration.
  29. func requestConfiguration() -> AuthRequestConfiguration
  30. func injectRecaptchaFields(recaptchaResponse: String?, recaptchaVersion: String)
  31. }
  32. // Default implementation of AuthRPCRequests. This produces similar behaviour to an optional method
  33. // in Obj-C.
  34. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  35. extension AuthRPCRequest {
  36. var containsPostBody: Bool { return true }
  37. func injectRecaptchaFields(recaptchaResponse: String?, recaptchaVersion: String) {
  38. fatalError("Internal FirebaseAuth Error: unimplemented injectRecaptchaFields")
  39. }
  40. }