EmailLinkSignInResponse.swift 2.3 KB

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