EmailLinkSignInResponse.swift 2.6 KB

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