AuthAppCredential.swift 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. /// A class represents a credential that proves the identity of the app.
  16. @objc(FIRAuthAppCredential) // objc Needed for decoding old versions
  17. class AuthAppCredential: NSObject, NSSecureCoding {
  18. /// The server acknowledgement of receiving client's claim of identity.
  19. var receipt: String
  20. /// The secret that the client received from server via a trusted channel, if ever.
  21. var secret: String?
  22. /// Initializes the instance.
  23. /// - Parameter receipt: The server acknowledgement of receiving client's claim of identity.
  24. /// - Parameter secret: The secret that the client received from server via a trusted channel, if
  25. /// ever.
  26. /// - Returns: The initialized instance.
  27. init(receipt: String, secret: String?) {
  28. self.secret = secret
  29. self.receipt = receipt
  30. }
  31. // MARK: NSSecureCoding
  32. private static let kReceiptKey = "receipt"
  33. private static let kSecretKey = "secret"
  34. static var supportsSecureCoding: Bool {
  35. true
  36. }
  37. required convenience init?(coder: NSCoder) {
  38. guard let receipt = coder.decodeObject(of: NSString.self,
  39. forKey: AuthAppCredential.kReceiptKey) as? String
  40. else {
  41. return nil
  42. }
  43. let secret = coder.decodeObject(of: NSString.self,
  44. forKey: AuthAppCredential.kSecretKey) as? String
  45. self.init(receipt: receipt, secret: secret)
  46. }
  47. func encode(with coder: NSCoder) {
  48. coder.encode(receipt, forKey: AuthAppCredential.kReceiptKey)
  49. coder.encode(secret, forKey: AuthAppCredential.kSecretKey)
  50. }
  51. }