PhoneMultiFactorInfo.swift 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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) open class PhoneMultiFactorInfo: MultiFactorInfo {
  22. /**
  23. @brief The string identifier for using phone as a second factor.
  24. This constant is available on iOS only.
  25. */
  26. @objc(FIRPhoneMultiFactorID) public static let PhoneMultiFactorID = "phone"
  27. /**
  28. @brief The string identifier for using TOTP as a second factor.
  29. This constant is available on iOS only.
  30. */
  31. @objc(FIRTOTPMultiFactorID) public static let TOTPMultiFactorID = "totp"
  32. /**
  33. @brief This is the phone number associated with the current second factor.
  34. */
  35. @objc open var phoneNumber: String
  36. init(proto: AuthProtoMFAEnrollment) {
  37. guard let phoneInfo = proto.phoneInfo else {
  38. fatalError("Internal Auth Error: Missing phone number in Multi Factor Enrollment")
  39. }
  40. phoneNumber = phoneInfo
  41. super.init(proto: proto, factorID: Self.PhoneMultiFactorID)
  42. }
  43. // MARK: NSSecureCoding
  44. private let kPhoneNumberCodingKey = "phoneNumber"
  45. override public class var supportsSecureCoding: Bool { return true }
  46. public required init?(coder: NSCoder) {
  47. guard let phoneNumber = coder.decodeObject(of: NSString.self,
  48. forKey: kPhoneNumberCodingKey) else {
  49. return nil
  50. }
  51. self.phoneNumber = phoneNumber as String
  52. super.init(coder: coder)
  53. }
  54. override public func encode(with coder: NSCoder) {
  55. super.encode(with: coder)
  56. coder.encode(phoneNumber, forKey: kPhoneNumberCodingKey)
  57. }
  58. }
  59. #endif