SendVerificationTokenRequest.swift 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. /** @var kSendVerificationCodeEndPoint
  16. @brief The "sendVerificationCodeEnd" endpoint.
  17. */
  18. private let kSendVerificationCodeEndPoint = "sendVerificationCode"
  19. /** @var kPhoneNumberKey
  20. @brief The key for the Phone Number parameter in the request.
  21. */
  22. private let kPhoneNumberKey = "phoneNumber"
  23. /** @var kReceiptKey
  24. @brief The key for the receipt parameter in the request.
  25. */
  26. private let kReceiptKey = "iosReceipt"
  27. /** @var kSecretKey
  28. @brief The key for the Secret parameter in the request.
  29. */
  30. private let kSecretKey = "iosSecret"
  31. /** @var kreCAPTCHATokenKey
  32. @brief The key for the reCAPTCHAToken parameter in the request.
  33. */
  34. private let kreCAPTCHATokenKey = "recaptchaToken"
  35. /** @var kTenantIDKey
  36. @brief The key for the tenant id value in the request.
  37. */
  38. private let kTenantIDKey = "tenantId"
  39. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  40. @objc(FIRSendVerificationCodeRequest)
  41. public class SendVerificationCodeRequest: IdentityToolkitRequest, AuthRPCRequest {
  42. /** @property phoneNumber
  43. @brief The phone number to which the verification code should be sent.
  44. */
  45. @objc public let phoneNumber: String
  46. /** @property appCredential
  47. @brief The credential to prove the identity of the app in order to send the verification code.
  48. */
  49. @objc public let appCredential: AuthAppCredential?
  50. /** @property reCAPTCHAToken
  51. @brief The reCAPTCHA token to prove the identity of the app in order to send the verification
  52. code.
  53. */
  54. @objc public let reCAPTCHAToken: String?
  55. /** @var response
  56. @brief The corresponding response for this request
  57. */
  58. @objc public var response: AuthRPCResponse = SendVerificationCodeResponse()
  59. @objc public init(phoneNumber: String, appCredential: AuthAppCredential?,
  60. reCAPTCHAToken: String?, requestConfiguration: AuthRequestConfiguration) {
  61. self.phoneNumber = phoneNumber
  62. self.appCredential = appCredential
  63. self.reCAPTCHAToken = reCAPTCHAToken
  64. super.init(
  65. endpoint: kSendVerificationCodeEndPoint,
  66. requestConfiguration: requestConfiguration
  67. )
  68. }
  69. @objc public func unencodedHTTPRequestBody() throws -> [String: AnyHashable] {
  70. var postBody: [String: AnyHashable] = [:]
  71. postBody[kPhoneNumberKey] = phoneNumber
  72. if let receipt = appCredential?.receipt {
  73. postBody[kReceiptKey] = receipt
  74. }
  75. if let secret = appCredential?.secret {
  76. postBody[kSecretKey] = secret
  77. }
  78. if let reCAPTCHAToken {
  79. postBody[kreCAPTCHATokenKey] = reCAPTCHAToken
  80. }
  81. if let tenantID {
  82. postBody[kTenantIDKey] = tenantID
  83. }
  84. return postBody
  85. }
  86. }