MultiFactorSession.swift 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #if os(iOS)
  16. /** @class FIRMultiFactorSession
  17. @brief Opaque object that identifies the current session to enroll a second factor or to
  18. complete sign in when previously enrolled. Identifies the current session to enroll a second factor or to complete sign in when
  19. previously enrolled. It contains additional context on the existing user, notably the confirmation
  20. that the user passed the first factor challenge.
  21. This class is available on iOS only.
  22. */
  23. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  24. @objc(FIRMultiFactorSession) open class MultiFactorSession: NSObject {
  25. /**
  26. @brief The ID token for an enroll flow. This has to be retrieved after recent authentication.
  27. */
  28. var idToken: String?
  29. /**
  30. @brief The pending credential after an enrolled second factor user signs in successfully with the
  31. first factor
  32. */
  33. var mfaPendingCredential: String?
  34. /**
  35. @brief Multi factor info for the current user.
  36. */
  37. var multiFactorInfo: MultiFactorInfo?
  38. /**
  39. @brief Current user object
  40. */
  41. var currentUser: User?
  42. class var sessionForCurrentUser: MultiFactorSession {
  43. // TODO: Fix for the right Auth instance. (broken in ObjC)
  44. guard let currentUser = Auth.auth().currentUser else {
  45. fatalError("Internal Auth Error: missing user for multifactor auth")
  46. }
  47. return .init(idToken: currentUser.tokenService.accessToken, currentUser: currentUser)
  48. }
  49. init(idToken: String, currentUser: User) {
  50. self.idToken = idToken
  51. self.currentUser = currentUser
  52. }
  53. init(mfaCredential: String?) {
  54. mfaPendingCredential = mfaCredential
  55. }
  56. }
  57. #endif