MultiFactorSession.swift 2.1 KB

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