FIRSetAccountInfoRequest.m 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 kReturnSecureTokenKey
  88. @brief The key for the "returnSecureToken" value in the request.
  89. */
  90. static NSString *const kReturnSecureTokenKey = @"returnSecureToken";
  91. /** @var kTenantIDKey
  92. @brief The key for the tenant id value in the request.
  93. */
  94. static NSString *const kTenantIDKey = @"tenantId";
  95. @implementation FIRSetAccountInfoRequest
  96. - (nullable instancetype)initWithRequestConfiguration:
  97. (FIRAuthRequestConfiguration *)requestConfiguration {
  98. self = [super initWithEndpoint:kSetAccountInfoEndpoint requestConfiguration:requestConfiguration];
  99. if (self) {
  100. _returnSecureToken = YES;
  101. }
  102. return self;
  103. }
  104. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
  105. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  106. if (_accessToken) {
  107. postBody[kIDTokenKey] = _accessToken;
  108. }
  109. if (_displayName) {
  110. postBody[kDisplayNameKey] = _displayName;
  111. }
  112. if (_localID) {
  113. postBody[kLocalIDKey] = _localID;
  114. }
  115. if (_email) {
  116. postBody[kEmailKey] = _email;
  117. }
  118. if (_password) {
  119. postBody[kPasswordKey] = _password;
  120. }
  121. if (_photoURL) {
  122. postBody[kPhotoURLKey] = _photoURL.absoluteString;
  123. }
  124. if (_providers) {
  125. postBody[kProvidersKey] = _providers;
  126. }
  127. if (_OOBCode) {
  128. postBody[kOOBCodeKey] = _OOBCode;
  129. }
  130. if (_emailVerified) {
  131. postBody[kEmailVerifiedKey] = @YES;
  132. }
  133. if (_upgradeToFederatedLogin) {
  134. postBody[kUpgradeToFederatedLoginKey] = @YES;
  135. }
  136. if (_captchaChallenge) {
  137. postBody[kCaptchaChallengeKey] = _captchaChallenge;
  138. }
  139. if (_captchaResponse) {
  140. postBody[kCaptchaResponseKey] = _captchaResponse;
  141. }
  142. if (_deleteAttributes) {
  143. postBody[kDeleteAttributesKey] = _deleteAttributes;
  144. }
  145. if (_deleteProviders) {
  146. postBody[kDeleteProvidersKey] = _deleteProviders;
  147. }
  148. if (_returnSecureToken) {
  149. postBody[kReturnSecureTokenKey] = @YES;
  150. }
  151. if (self.tenantID) {
  152. postBody[kTenantIDKey] = self.tenantID;
  153. }
  154. return [postBody copy];
  155. }
  156. @end
  157. NS_ASSUME_NONNULL_END