No Description

FIRSetAccountInfoRequest.m 5.2KB

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