VerifyPasswordResponse.swift 2.6 KB

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