AuthAppCredential.swift 2.3 KB

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