PhoneMultiFactorInfo.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #if os(iOS)
  16. /** @class FIRPhoneMultiFactorInfo
  17. @brief Extends the MultiFactorInfo class for phone number second factors.
  18. The identifier of this second factor is "phone".
  19. This class is available on iOS only.
  20. */
  21. @objc(FIRPhoneMultiFactorInfo) public class PhoneMultiFactorInfo: MultiFactorInfo {
  22. @objc(FIRPhoneMultiFactorID) public static let PhoneMultiFactorID = "FIRPhoneMultiFactorID"
  23. /**
  24. @brief This is the phone number associated with the current second factor.
  25. */
  26. @objc public var phoneNumber: String
  27. @objc override public init(proto: AuthProtoMFAEnrollment) {
  28. guard let phoneInfo = proto.phoneInfo else {
  29. fatalError("Internal Auth Error: Missing phone number in Multi Factor Enrollment")
  30. }
  31. phoneNumber = phoneInfo
  32. super.init(proto: proto)
  33. factorID = Self.PhoneMultiFactorID
  34. }
  35. // MARK: NSSecureCoding
  36. private let kPhoneNumberCodingKey = "phoneNumber"
  37. private static var secureCodingWorkaround = true
  38. override public class var supportsSecureCoding: Bool { return secureCodingWorkaround }
  39. public required init?(coder: NSCoder) {
  40. guard let phoneNumber = coder.decodeObject(forKey: kPhoneNumberCodingKey) as? String else {
  41. return nil
  42. }
  43. self.phoneNumber = phoneNumber
  44. super.init(coder: coder)
  45. }
  46. override public func encode(with coder: NSCoder) {
  47. super.encode(with: coder)
  48. coder.encode(phoneNumber, forKey: kPhoneNumberCodingKey)
  49. }
  50. }
  51. #endif