AuthAppCredential.swift 2.1 KB

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