PhoneMultiFactorInfo.swift 2.2 KB

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