AuthProtoStartMFAPhoneRequestInfo.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 key for the Phone Number parameter in the request.
  16. private let kPhoneNumberKey = "phoneNumber"
  17. /// The key for the receipt parameter in the request.
  18. private let kReceiptKey = "iosReceipt"
  19. /// The key for the Secret parameter in the request.
  20. private let kSecretKey = "iosSecret"
  21. /// The key for the reCAPTCHAToken parameter in the request.
  22. private let kreCAPTCHATokenKey = "recaptchaToken"
  23. class AuthProtoStartMFAPhoneRequestInfo: NSObject, AuthProto {
  24. required init(dictionary: [String: AnyHashable]) {
  25. fatalError()
  26. }
  27. var phoneNumber: String?
  28. var codeIdentity: CodeIdentity
  29. init(phoneNumber: String?, codeIdentity: CodeIdentity) {
  30. self.phoneNumber = phoneNumber
  31. self.codeIdentity = codeIdentity
  32. }
  33. var dictionary: [String: AnyHashable] {
  34. var dict: [String: AnyHashable] = [:]
  35. if let phoneNumber = phoneNumber {
  36. dict[kPhoneNumberKey] = phoneNumber
  37. }
  38. switch codeIdentity {
  39. case let .credential(appCredential):
  40. dict[kReceiptKey] = appCredential.receipt
  41. dict[kSecretKey] = appCredential.secret
  42. case let .recaptcha(reCAPTCHAToken):
  43. dict[kreCAPTCHATokenKey] = reCAPTCHAToken
  44. case .empty:
  45. break
  46. }
  47. return dict
  48. }
  49. }