VerifyPasswordResponse.swift 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 verifyPassword endpoint.
  16. ///
  17. /// Possible error codes:
  18. /// * FIRAuthInternalErrorCodeUserDisabled
  19. /// * FIRAuthInternalErrorCodeEmailNotFound
  20. ///
  21. /// See https: // developers.google.com/identity/toolkit/web/reference/relyingparty/verifyPassword
  22. class VerifyPasswordResponse: AuthRPCResponse, AuthMFAResponse {
  23. required init() {}
  24. /// The RP local ID if it's already been mapped to the IdP account identified by the federated ID.
  25. var localID: String?
  26. /// The email returned by the IdP. NOTE: The federated login user may not own the email.
  27. var email: String?
  28. /// The display name of the user.
  29. var displayName: String?
  30. /// Either an authorization code suitable for performing an STS token exchange, or the
  31. /// access token from Secure Token Service, depending on whether `returnSecureToken` is set
  32. /// on the request.
  33. private(set) var idToken: String?
  34. /// The approximate expiration date of the access token.
  35. var approximateExpirationDate: Date?
  36. /// The refresh token from Secure Token Service.
  37. var refreshToken: String?
  38. /// The URI of the accessible profile picture.
  39. var photoURL: URL?
  40. // MARK: - AuthMFAResponse
  41. private(set) var mfaPendingCredential: String?
  42. private(set) var mfaInfo: [AuthProtoMFAEnrollment]?
  43. func setFields(dictionary: [String: AnyHashable]) throws {
  44. localID = dictionary["localId"] as? String
  45. email = dictionary["email"] as? String
  46. displayName = dictionary["displayName"] as? String
  47. idToken = dictionary["idToken"] as? String
  48. if let expiresIn = dictionary["expiresIn"] as? String {
  49. approximateExpirationDate = Date(timeIntervalSinceNow: (expiresIn as NSString)
  50. .doubleValue)
  51. }
  52. refreshToken = dictionary["refreshToken"] as? String
  53. photoURL = (dictionary["photoUrl"] as? String).flatMap { URL(string: $0) }
  54. if let mfaInfo = dictionary["mfaInfo"] as? [[String: AnyHashable]] {
  55. self.mfaInfo = mfaInfo.map { AuthProtoMFAEnrollment(dictionary: $0) }
  56. }
  57. mfaPendingCredential = dictionary["mfaPendingCredential"] as? String
  58. }
  59. }