AuthAppCredential.swift 2.2 KB

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