VerifyPhoneNumberResponse.swift 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 VerifyPhoneNumberResponse: AuthRPCResponse {
  16. required init() {}
  17. /** @property IDToken
  18. @brief Either an authorization code suitable for performing an STS token exchange, or the
  19. access token from Secure Token Service, depending on whether @c returnSecureToken is set
  20. on the request.
  21. */
  22. var idToken: String?
  23. /** @property refreshToken
  24. @brief The refresh token from Secure Token Service.
  25. */
  26. var refreshToken: String?
  27. /** @property localID
  28. @brief The Firebase Auth user ID.
  29. */
  30. var localID: String?
  31. /** @property phoneNumber
  32. @brief The verified phone number.
  33. */
  34. var phoneNumber: String?
  35. /** @property temporaryProof
  36. @brief The temporary proof code returned by the backend.
  37. */
  38. var temporaryProof: String?
  39. /** @property isNewUser
  40. @brief Flag indicating that the user signing in is a new user and not a returning user.
  41. */
  42. var isNewUser: Bool = false
  43. /** @property approximateExpirationDate
  44. @brief The approximate expiration date of the access token.
  45. */
  46. var approximateExpirationDate: Date?
  47. // XXX TODO: What might this be?
  48. func expectedKind() -> String? {
  49. nil
  50. }
  51. func setFields(dictionary: [String: AnyHashable]) throws {
  52. idToken = dictionary["idToken"] as? String
  53. refreshToken = dictionary["refreshToken"] as? String
  54. isNewUser = (dictionary["isNewUser"] as? Bool) ?? false
  55. localID = dictionary["localId"] as? String
  56. phoneNumber = dictionary["phoneNumber"] as? String
  57. temporaryProof = dictionary["temporaryProof"] as? String
  58. if let expiresIn = dictionary["expiresIn"] as? String {
  59. approximateExpirationDate = Date(timeIntervalSinceNow: (expiresIn as NSString)
  60. .doubleValue)
  61. }
  62. }
  63. }