VerifyPasswordResponse.swift 2.9 KB

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