SetAccountInfoResponse.swift 3.5 KB

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