EmailLinkSignInResponse.swift 2.6 KB

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