AuthDataResult.swift 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. /// The signed in user.
  24. @objc public let user: User
  25. /// If available, contains the additional IdP specific information about signed in user.
  26. @objc public let additionalUserInfo: AdditionalUserInfo?
  27. /// This property will be non-nil after a successful headful-lite sign-in via
  28. /// `signIn(with:uiDelegate:completion:)`.
  29. ///
  30. /// May be used to obtain the accessToken and/or IDToken
  31. /// pertaining to a recently signed-in user.
  32. @objc public let credential: OAuthCredential?
  33. /// Designated initializer.
  34. /// - Parameter user: The signed in user reference.
  35. /// - Parameter additionalUserInfo: The additional user info.
  36. /// - Parameter credential: The updated OAuth credential if available.
  37. init(withUser user: User,
  38. additionalUserInfo: AdditionalUserInfo?,
  39. credential: OAuthCredential? = nil) {
  40. self.user = user
  41. self.additionalUserInfo = additionalUserInfo
  42. self.credential = credential
  43. }
  44. // MARK: Secure Coding
  45. private let kAdditionalUserInfoCodingKey = "additionalUserInfo"
  46. private let kUserCodingKey = "user"
  47. private let kCredentialCodingKey = "credential"
  48. public static let supportsSecureCoding = true
  49. public func encode(with coder: NSCoder) {
  50. coder.encode(user, forKey: kUserCodingKey)
  51. coder.encode(additionalUserInfo, forKey: kAdditionalUserInfoCodingKey)
  52. coder.encode(credential, forKey: kCredentialCodingKey)
  53. }
  54. public required init?(coder: NSCoder) {
  55. guard let user = coder.decodeObject(of: User.self, forKey: kUserCodingKey) else {
  56. return nil
  57. }
  58. self.user = user
  59. additionalUserInfo = coder.decodeObject(of: AdditionalUserInfo.self,
  60. forKey: kAdditionalUserInfoCodingKey)
  61. credential = coder.decodeObject(of: OAuthCredential.self, forKey: kCredentialCodingKey)
  62. }
  63. }