AuthAppCredential.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. final class AuthAppCredential: NSObject, NSSecureCoding, Sendable {
  18. /// The server acknowledgement of receiving client's claim of identity.
  19. let receipt: String
  20. /// The secret that the client received from server via a trusted channel, if ever.
  21. let 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 let supportsSecureCoding = true
  35. required convenience init?(coder: NSCoder) {
  36. guard let receipt = coder.decodeObject(of: NSString.self,
  37. forKey: AuthAppCredential.kReceiptKey) as? String
  38. else {
  39. return nil
  40. }
  41. let secret = coder.decodeObject(of: NSString.self,
  42. forKey: AuthAppCredential.kSecretKey) as? String
  43. self.init(receipt: receipt, secret: secret)
  44. }
  45. func encode(with coder: NSCoder) {
  46. coder.encode(receipt, forKey: AuthAppCredential.kReceiptKey)
  47. coder.encode(secret, forKey: AuthAppCredential.kSecretKey)
  48. }
  49. }