FIRSetAccountInfoRequest.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 "FIRSetAccountInfoRequest.h"
  17. #import "FIRAuthErrorUtils.h"
  18. #import "FIRAuth_Internal.h"
  19. #import "FIRGetAccountInfoResponse.h"
  20. NSString *const FIRSetAccountInfoUserAttributeEmail = @"EMAIL";
  21. NSString *const FIRSetAccountInfoUserAttributeDisplayName = @"DISPLAY_NAME";
  22. NSString *const FIRSetAccountInfoUserAttributeProvider = @"PROVIDER";
  23. NSString *const FIRSetAccountInfoUserAttributePhotoURL = @"PHOTO_URL";
  24. NSString *const FIRSetAccountInfoUserAttributePassword = @"PASSWORD";
  25. /** @var kCreateAuthURIEndpoint
  26. @brief The "setAccountInfo" endpoint.
  27. */
  28. static NSString *const kSetAccountInfoEndpoint = @"setAccountInfo";
  29. /** @var kIDTokenKey
  30. @brief The key for the "idToken" value in the request. This is actually the STS Access Token,
  31. despite it's confusing (backwards compatiable) parameter name.
  32. */
  33. static NSString *const kIDTokenKey = @"idToken";
  34. /** @var kDisplayNameKey
  35. @brief The key for the "displayName" value in the request.
  36. */
  37. static NSString *const kDisplayNameKey = @"displayName";
  38. /** @var kLocalIDKey
  39. @brief The key for the "localID" value in the request.
  40. */
  41. static NSString *const kLocalIDKey = @"localId";
  42. /** @var kEmailKey
  43. @brief The key for the "email" value in the request.
  44. */
  45. static NSString *const kEmailKey = @"email";
  46. /** @var kPasswordKey
  47. @brief The key for the "password" value in the request.
  48. */
  49. static NSString *const kPasswordKey = @"password";
  50. /** @var kPhotoURLKey
  51. @brief The key for the "photoURL" value in the request.
  52. */
  53. static NSString *const kPhotoURLKey = @"photoUrl";
  54. /** @var kProvidersKey
  55. @brief The key for the "providers" value in the request.
  56. */
  57. static NSString *const kProvidersKey = @"provider";
  58. /** @var kOOBCodeKey
  59. @brief The key for the "OOBCode" value in the request.
  60. */
  61. static NSString *const kOOBCodeKey = @"oobCode";
  62. /** @var kEmailVerifiedKey
  63. @brief The key for the "emailVerified" value in the request.
  64. */
  65. static NSString *const kEmailVerifiedKey = @"emailVerified";
  66. /** @var kUpgradeToFederatedLoginKey
  67. @brief The key for the "upgradeToFederatedLogin" value in the request.
  68. */
  69. static NSString *const kUpgradeToFederatedLoginKey = @"upgradeToFederatedLogin";
  70. /** @var kCaptchaChallengeKey
  71. @brief The key for the "captchaChallenge" value in the request.
  72. */
  73. static NSString *const kCaptchaChallengeKey = @"captchaChallenge";
  74. /** @var kCaptchaResponseKey
  75. @brief The key for the "captchaResponse" value in the request.
  76. */
  77. static NSString *const kCaptchaResponseKey = @"captchaResponse";
  78. /** @var kDeleteAttributesKey
  79. @brief The key for the "deleteAttribute" value in the request.
  80. */
  81. static NSString *const kDeleteAttributesKey = @"deleteAttribute";
  82. /** @var kDeleteProvidersKey
  83. @brief The key for the "deleteProvider" value in the request.
  84. */
  85. static NSString *const kDeleteProvidersKey = @"deleteProvider";
  86. /** @var kReturnSecureTokenKey
  87. @brief The key for the "returnSecureToken" value in the request.
  88. */
  89. static NSString *const kReturnSecureTokenKey = @"returnSecureToken";
  90. @implementation FIRSetAccountInfoRequest
  91. - (nullable instancetype)initWithAPIKey:(NSString *)APIKey {
  92. self = [super initWithEndpoint:kSetAccountInfoEndpoint APIKey:APIKey];
  93. if (self) {
  94. _returnSecureToken = YES;
  95. }
  96. return self;
  97. }
  98. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
  99. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  100. if (_accessToken) {
  101. postBody[kIDTokenKey] = _accessToken;
  102. }
  103. if (_displayName) {
  104. postBody[kDisplayNameKey] = _displayName;
  105. }
  106. if (_localID) {
  107. postBody[kLocalIDKey] = _localID;
  108. }
  109. if (_email) {
  110. postBody[kEmailKey] = _email;
  111. }
  112. if (_password) {
  113. postBody[kPasswordKey] = _password;
  114. }
  115. if (_photoURL) {
  116. postBody[kPhotoURLKey] = _photoURL.absoluteString;
  117. }
  118. if (_providers) {
  119. postBody[kProvidersKey] = _providers;
  120. }
  121. if (_OOBCode) {
  122. postBody[kOOBCodeKey] = _OOBCode;
  123. }
  124. if (_emailVerified) {
  125. postBody[kEmailVerifiedKey] = @YES;
  126. }
  127. if (_upgradeToFederatedLogin) {
  128. postBody[kUpgradeToFederatedLoginKey] = @YES;
  129. }
  130. if (_captchaChallenge) {
  131. postBody[kCaptchaChallengeKey] = _captchaChallenge;
  132. }
  133. if (_captchaResponse) {
  134. postBody[kCaptchaResponseKey] = _captchaResponse;
  135. }
  136. if (_deleteAttributes) {
  137. postBody[kDeleteAttributesKey] = _deleteAttributes;
  138. }
  139. if (_deleteProviders) {
  140. postBody[kDeleteProvidersKey] = _deleteProviders;
  141. }
  142. if (_returnSecureToken) {
  143. postBody[kReturnSecureTokenKey] = @YES;
  144. }
  145. return postBody;
  146. }
  147. @end