AuthDataResult.swift 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  16. extension AuthDataResult: NSSecureCoding {}
  17. /// Helper object that contains the result of a successful sign-in, link and reauthenticate
  18. /// action.
  19. ///
  20. /// It contains references to a `User` instance and an `AdditionalUserInfo` instance.
  21. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  22. @objc(FIRAuthDataResult) open class AuthDataResult: NSObject,
  23. @unchecked Sendable /* TODO: sendable */ {
  24. /// The signed in user.
  25. @objc public let user: User
  26. /// If available, contains the additional IdP specific information about signed in user.
  27. @objc public let additionalUserInfo: AdditionalUserInfo?
  28. /// This property will be non-nil after a successful headful-lite sign-in via
  29. /// `signIn(with:uiDelegate:completion:)`.
  30. ///
  31. /// May be used to obtain the accessToken and/or IDToken
  32. /// pertaining to a recently signed-in user.
  33. @objc public let credential: OAuthCredential?
  34. /// Designated initializer.
  35. /// - Parameter user: The signed in user reference.
  36. /// - Parameter additionalUserInfo: The additional user info.
  37. /// - Parameter credential: The updated OAuth credential if available.
  38. init(withUser user: User,
  39. additionalUserInfo: AdditionalUserInfo?,
  40. credential: OAuthCredential? = nil) {
  41. self.user = user
  42. self.additionalUserInfo = additionalUserInfo
  43. self.credential = credential
  44. }
  45. // MARK: Secure Coding
  46. private let kAdditionalUserInfoCodingKey = "additionalUserInfo"
  47. private let kUserCodingKey = "user"
  48. private let kCredentialCodingKey = "credential"
  49. public static let supportsSecureCoding = true
  50. public func encode(with coder: NSCoder) {
  51. coder.encode(user, forKey: kUserCodingKey)
  52. coder.encode(additionalUserInfo, forKey: kAdditionalUserInfoCodingKey)
  53. coder.encode(credential, forKey: kCredentialCodingKey)
  54. }
  55. public required init?(coder: NSCoder) {
  56. guard let user = coder.decodeObject(of: User.self, forKey: kUserCodingKey) else {
  57. return nil
  58. }
  59. self.user = user
  60. additionalUserInfo = coder.decodeObject(of: AdditionalUserInfo.self,
  61. forKey: kAdditionalUserInfoCodingKey)
  62. credential = coder.decodeObject(of: OAuthCredential.self, forKey: kCredentialCodingKey)
  63. }
  64. }