VerifyPhoneNumberResponse.swift 2.0 KB

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