AuthAppCredential.swift 2.4 KB

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