MultiFactorSession.swift 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 var sessionForCurrentUser: MultiFactorSession {
  36. guard let currentUser = Auth.auth().currentUser else {
  37. fatalError("Internal Auth Error: missing user for multifactor auth")
  38. }
  39. return .init(idToken: currentUser.tokenService.accessToken, currentUser: currentUser)
  40. }
  41. init(idToken: String, currentUser: User) {
  42. self.idToken = idToken
  43. self.currentUser = currentUser
  44. }
  45. init(mfaCredential: String?) {
  46. mfaPendingCredential = mfaCredential
  47. }
  48. }
  49. #endif