SetAccountInfoResponse.swift 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. /// Represents the response from the setAccountInfo endpoint.
  16. /// See https: // developers.google.com/identity/toolkit/web/reference/relyingparty/setAccountInfo
  17. struct SetAccountInfoResponse: AuthRPCResponse {
  18. /// Represents the provider user info part of the response from the setAccountInfo endpoint.
  19. /// See https: // developers.google.com/identity/toolkit/web/reference/relyingparty/setAccountInfo
  20. struct ProviderUserInfo {
  21. /// The ID of the identity provider.
  22. var providerID: String?
  23. /// The user's display name at the identity provider.
  24. var displayName: String?
  25. /// The user's photo URL at the identity provider.
  26. var photoURL: URL?
  27. /// Designated initializer.
  28. /// - Parameter dictionary: The provider user info data from endpoint.
  29. init(dictionary: [String: Any]) {
  30. providerID = dictionary["providerId"] as? String
  31. displayName = dictionary["displayName"] as? String
  32. if let photoURL = dictionary["photoUrl"] as? String {
  33. self.photoURL = URL(string: photoURL)
  34. }
  35. }
  36. }
  37. /// The email or the user.
  38. var email: String?
  39. /// The display name of the user.
  40. var displayName: String?
  41. /// The user's profiles at the associated identity providers.
  42. var providerUserInfo: [Self.ProviderUserInfo]?
  43. /// Either an authorization code suitable for performing an STS token exchange, or the
  44. /// access token from Secure Token Service, depending on whether `returnSecureToken` is set
  45. /// on the request.
  46. var idToken: String?
  47. /// The approximate expiration date of the access token.
  48. var approximateExpirationDate: Date?
  49. /// The refresh token from Secure Token Service.
  50. var refreshToken: String?
  51. init(dictionary: [String: AnyHashable]) throws {
  52. email = dictionary["email"] as? String
  53. displayName = dictionary["displayName"] as? String
  54. idToken = dictionary["idToken"] as? String
  55. if let expiresIn = dictionary["expiresIn"] as? String {
  56. approximateExpirationDate = Date(timeIntervalSinceNow: (expiresIn as NSString)
  57. .doubleValue)
  58. }
  59. refreshToken = dictionary["refreshToken"] as? String
  60. if let providerUserInfoData = dictionary["providerUserInfo"] as? [[String: Any]] {
  61. providerUserInfo = providerUserInfoData.map { .init(dictionary: $0) }
  62. }
  63. }
  64. }