AuthDataResult.swift 3.0 KB

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