You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
5.1 KiB

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