EmailLinkSignInResponse.swift 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. /** @class FIRVerifyAssertionResponse
  16. @brief Represents the response from the emailLinkSignin endpoint.
  17. */
  18. class EmailLinkSignInResponse: NSObject, AuthRPCResponse, AuthMFAResponse {
  19. override required init() {}
  20. /** @property IDToken
  21. @brief The ID token in the email link sign-in response.
  22. */
  23. private(set) var idToken: String?
  24. /** @property email
  25. @brief The email returned by the IdP.
  26. */
  27. var email: String?
  28. /** @property refreshToken
  29. @brief The refreshToken returned by the server.
  30. */
  31. var refreshToken: String?
  32. /** @property approximateExpirationDate
  33. @brief The approximate expiration date of the access token.
  34. */
  35. var approximateExpirationDate: Date?
  36. /** @property isNewUser
  37. @brief Flag indicating that the user signing in is a new user and not a returning user.
  38. */
  39. var isNewUser: Bool = false
  40. // MARK: - AuthMFAResponse
  41. /** @property MFAPendingCredential
  42. @brief An opaque string that functions as proof that the user has successfully passed the first
  43. factor check.
  44. */
  45. private(set) var mfaPendingCredential: String?
  46. /** @property MFAInfo
  47. @brief Info on which multi-factor authentication providers are enabled.
  48. */
  49. private(set) var mfaInfo: [AuthProtoMFAEnrollment]?
  50. func setFields(dictionary: [String: AnyHashable]) throws {
  51. email = dictionary["email"] as? String
  52. idToken = dictionary["idToken"] as? String
  53. isNewUser = dictionary["isNewUser"] as? Bool ?? false
  54. refreshToken = dictionary["refreshToken"] as? String
  55. approximateExpirationDate = (dictionary["expiresIn"] as? String)
  56. .flatMap { Date(timeIntervalSinceNow: ($0 as NSString).doubleValue)
  57. }
  58. if let mfaInfoArray = dictionary["mfaInfo"] as? [[String: AnyHashable]] {
  59. var mfaInfo: [AuthProtoMFAEnrollment] = []
  60. for entry in mfaInfoArray {
  61. let enrollment = AuthProtoMFAEnrollment(dictionary: entry)
  62. mfaInfo.append(enrollment)
  63. }
  64. self.mfaInfo = mfaInfo
  65. }
  66. mfaPendingCredential = dictionary["mfaPendingCredential"] as? String
  67. }
  68. }