SignInWithGameCenterResponse.swift 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 SignInWithGameCenterResponse: AuthRPCResponse {
  16. required init() {}
  17. var idToken: String?
  18. var refreshToken: String?
  19. var localID: String?
  20. var playerID: String?
  21. var teamPlayerID: String?
  22. var gamePlayerID: String?
  23. var approximateExpirationDate: Date?
  24. var isNewUser: Bool = false
  25. var displayName: String?
  26. func setFields(dictionary: [String: AnyHashable]) throws {
  27. idToken = dictionary["idToken"] as? String
  28. refreshToken = dictionary["refreshToken"] as? String
  29. localID = dictionary["localId"] as? String
  30. if let approximateExpirationDate = dictionary["expiresIn"] as? String {
  31. self
  32. .approximateExpirationDate =
  33. Date(timeIntervalSinceNow: (approximateExpirationDate as NSString).doubleValue)
  34. }
  35. refreshToken = dictionary["refreshToken"] as? String
  36. playerID = dictionary["playerId"] as? String
  37. teamPlayerID = dictionary["teamPlayerId"] as? String
  38. gamePlayerID = dictionary["gamePlayerId"] as? String
  39. isNewUser = dictionary["isNewUser"] as? Bool ?? false
  40. displayName = dictionary["displayName"] as? String
  41. }
  42. }