FIRSetAccountInfoRequest.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "FirebaseAuth/Sources/Backend/RPC/FIRSetAccountInfoRequest.h"
  17. #import "FirebaseAuth/Sources/Auth/FIRAuth_Internal.h"
  18. #import "FirebaseAuth/Sources/Backend/RPC/FIRGetAccountInfoResponse.h"
  19. #import "FirebaseAuth/Sources/Utilities/FIRAuthErrorUtils.h"
  20. NS_ASSUME_NONNULL_BEGIN
  21. NSString *const FIRSetAccountInfoUserAttributeEmail = @"EMAIL";
  22. NSString *const FIRSetAccountInfoUserAttributeDisplayName = @"DISPLAY_NAME";
  23. NSString *const FIRSetAccountInfoUserAttributeProvider = @"PROVIDER";
  24. NSString *const FIRSetAccountInfoUserAttributePhotoURL = @"PHOTO_URL";
  25. NSString *const FIRSetAccountInfoUserAttributePassword = @"PASSWORD";
  26. /** @var kCreateAuthURIEndpoint
  27. @brief The "setAccountInfo" endpoint.
  28. */
  29. static NSString *const kSetAccountInfoEndpoint = @"setAccountInfo";
  30. /** @var kIDTokenKey
  31. @brief The key for the "idToken" value in the request. This is actually the STS Access Token,
  32. despite it's confusing (backwards compatiable) parameter name.
  33. */
  34. static NSString *const kIDTokenKey = @"idToken";
  35. /** @var kDisplayNameKey
  36. @brief The key for the "displayName" value in the request.
  37. */
  38. static NSString *const kDisplayNameKey = @"displayName";
  39. /** @var kLocalIDKey
  40. @brief The key for the "localID" value in the request.
  41. */
  42. static NSString *const kLocalIDKey = @"localId";
  43. /** @var kEmailKey
  44. @brief The key for the "email" value in the request.
  45. */
  46. static NSString *const kEmailKey = @"email";
  47. /** @var kPasswordKey
  48. @brief The key for the "password" value in the request.
  49. */
  50. static NSString *const kPasswordKey = @"password";
  51. /** @var kPhotoURLKey
  52. @brief The key for the "photoURL" value in the request.
  53. */
  54. static NSString *const kPhotoURLKey = @"photoUrl";
  55. /** @var kProvidersKey
  56. @brief The key for the "providers" value in the request.
  57. */
  58. static NSString *const kProvidersKey = @"provider";
  59. /** @var kOOBCodeKey
  60. @brief The key for the "OOBCode" value in the request.
  61. */
  62. static NSString *const kOOBCodeKey = @"oobCode";
  63. /** @var kEmailVerifiedKey
  64. @brief The key for the "emailVerified" value in the request.
  65. */
  66. static NSString *const kEmailVerifiedKey = @"emailVerified";
  67. /** @var kUpgradeToFederatedLoginKey
  68. @brief The key for the "upgradeToFederatedLogin" value in the request.
  69. */
  70. static NSString *const kUpgradeToFederatedLoginKey = @"upgradeToFederatedLogin";
  71. /** @var kCaptchaChallengeKey
  72. @brief The key for the "captchaChallenge" value in the request.
  73. */
  74. static NSString *const kCaptchaChallengeKey = @"captchaChallenge";
  75. /** @var kCaptchaResponseKey
  76. @brief The key for the "captchaResponse" value in the request.
  77. */
  78. static NSString *const kCaptchaResponseKey = @"captchaResponse";
  79. /** @var kDeleteAttributesKey
  80. @brief The key for the "deleteAttribute" value in the request.
  81. */
  82. static NSString *const kDeleteAttributesKey = @"deleteAttribute";
  83. /** @var kDeleteProvidersKey
  84. @brief The key for the "deleteProvider" value in the request.
  85. */
  86. static NSString *const kDeleteProvidersKey = @"deleteProvider";
  87. /** @var kDeletePasskeysKey
  88. @brief The key for the "deletePasskey" value in the request.
  89. */
  90. static NSString *const kDeletePasskeysKey = @"deletePasskey";
  91. /** @var kReturnSecureTokenKey
  92. @brief The key for the "returnSecureToken" value in the request.
  93. */
  94. static NSString *const kReturnSecureTokenKey = @"returnSecureToken";
  95. /** @var kTenantIDKey
  96. @brief The key for the tenant id value in the request.
  97. */
  98. static NSString *const kTenantIDKey = @"tenantId";
  99. @implementation FIRSetAccountInfoRequest
  100. - (nullable instancetype)initWithRequestConfiguration:
  101. (FIRAuthRequestConfiguration *)requestConfiguration {
  102. self = [super initWithEndpoint:kSetAccountInfoEndpoint requestConfiguration:requestConfiguration];
  103. if (self) {
  104. _returnSecureToken = YES;
  105. }
  106. return self;
  107. }
  108. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
  109. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  110. if (_accessToken) {
  111. postBody[kIDTokenKey] = _accessToken;
  112. }
  113. if (_displayName) {
  114. postBody[kDisplayNameKey] = _displayName;
  115. }
  116. if (_localID) {
  117. postBody[kLocalIDKey] = _localID;
  118. }
  119. if (_email) {
  120. postBody[kEmailKey] = _email;
  121. }
  122. if (_password) {
  123. postBody[kPasswordKey] = _password;
  124. }
  125. if (_photoURL) {
  126. postBody[kPhotoURLKey] = _photoURL.absoluteString;
  127. }
  128. if (_providers) {
  129. postBody[kProvidersKey] = _providers;
  130. }
  131. if (_OOBCode) {
  132. postBody[kOOBCodeKey] = _OOBCode;
  133. }
  134. if (_emailVerified) {
  135. postBody[kEmailVerifiedKey] = @YES;
  136. }
  137. if (_upgradeToFederatedLogin) {
  138. postBody[kUpgradeToFederatedLoginKey] = @YES;
  139. }
  140. if (_captchaChallenge) {
  141. postBody[kCaptchaChallengeKey] = _captchaChallenge;
  142. }
  143. if (_captchaResponse) {
  144. postBody[kCaptchaResponseKey] = _captchaResponse;
  145. }
  146. if (_deleteAttributes) {
  147. postBody[kDeleteAttributesKey] = _deleteAttributes;
  148. }
  149. if (_deletePasskeys) {
  150. postBody[kDeletePasskeysKey] = _deletePasskeys;
  151. }
  152. if (_deleteProviders) {
  153. postBody[kDeleteProvidersKey] = _deleteProviders;
  154. }
  155. if (_returnSecureToken) {
  156. postBody[kReturnSecureTokenKey] = @YES;
  157. }
  158. if (self.tenantID) {
  159. postBody[kTenantIDKey] = self.tenantID;
  160. }
  161. return [postBody copy];
  162. }
  163. @end
  164. NS_ASSUME_NONNULL_END