VerifyPhoneNumberResponse.swift 2.0 KB

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