SetAccountInfoResponse.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 FIRSetAccountInfoResponseProviderUserInfo
  16. @brief Represents the provider user info part of the response from the setAccountInfo endpoint.
  17. @see https://developers.google.com/identity/toolkit/web/reference/relyingparty/setAccountInfo
  18. */
  19. class SetAccountInfoResponseProviderUserInfo: NSObject {
  20. /** @property providerID
  21. @brief The ID of the identity provider.
  22. */
  23. var providerID: String?
  24. /** @property displayName
  25. @brief The user's display name at the identity provider.
  26. */
  27. var displayName: String?
  28. /** @property photoURL
  29. @brief The user's photo URL at the identity provider.
  30. */
  31. var photoURL: URL?
  32. /** @fn initWithAPIKey:
  33. @brief Designated initializer.
  34. @param dictionary The provider user info data from endpoint.
  35. */
  36. init(dictionary: [String: Any]) {
  37. providerID = dictionary["providerId"] as? String
  38. displayName = dictionary["displayName"] as? String
  39. if let photoURL = dictionary["photoUrl"] as? String {
  40. self.photoURL = URL(string: photoURL)
  41. }
  42. }
  43. }
  44. /** @class FIRSetAccountInfoResponse
  45. @brief Represents the response from the setAccountInfo endpoint.
  46. @see https://developers.google.com/identity/toolkit/web/reference/relyingparty/setAccountInfo
  47. */
  48. class SetAccountInfoResponse: AuthRPCResponse {
  49. required init() {}
  50. /** @property email
  51. @brief The email or the user.
  52. */
  53. var email: String?
  54. /** @property displayName
  55. @brief The display name of the user.
  56. */
  57. var displayName: String?
  58. /** @property providerUserInfo
  59. @brief The user's profiles at the associated identity providers.
  60. */
  61. var providerUserInfo: [SetAccountInfoResponseProviderUserInfo]?
  62. /** @property idToken
  63. @brief Either an authorization code suitable for performing an STS token exchange, or the
  64. access token from Secure Token Service, depending on whether @c returnSecureToken is set
  65. on the request.
  66. */
  67. var idToken: String?
  68. /** @property approximateExpirationDate
  69. @brief The approximate expiration date of the access token.
  70. */
  71. var approximateExpirationDate: Date?
  72. /** @property refreshToken
  73. @brief The refresh token from Secure Token Service.
  74. */
  75. var refreshToken: String?
  76. func setFields(dictionary: [String: AnyHashable]) throws {
  77. email = dictionary["email"] as? String
  78. displayName = dictionary["displayName"] as? String
  79. idToken = dictionary["idToken"] as? String
  80. if let expiresIn = dictionary["expiresIn"] as? String {
  81. approximateExpirationDate = Date(timeIntervalSinceNow: (expiresIn as NSString)
  82. .doubleValue)
  83. }
  84. refreshToken = dictionary["refreshToken"] as? String
  85. if let providerUserInfoData = dictionary["providerUserInfo"] as? [[String: Any]] {
  86. providerUserInfo = providerUserInfoData.map { .init(dictionary: $0) }
  87. }
  88. }
  89. }