FIRSignUpNewUserRequest.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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/FIRSignUpNewUserRequest.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. /** @var kSignupNewUserEndpoint
  19. @brief The "SingupNewUserEndpoint" endpoint.
  20. */
  21. static NSString *const kSignupNewUserEndpoint = @"signupNewUser";
  22. /** @var kEmailKey
  23. @brief The key for the "email" value in the request.
  24. */
  25. static NSString *const kEmailKey = @"email";
  26. /** @var kPasswordKey
  27. @brief The key for the "password" value in the request.
  28. */
  29. static NSString *const kPasswordKey = @"password";
  30. /** @var kDisplayNameKey
  31. @brief The key for the "kDisplayName" value in the request.
  32. */
  33. static NSString *const kDisplayNameKey = @"displayName";
  34. /** @var kIDToken
  35. @brief The key for the "kIDToken" value in the request.
  36. */
  37. static NSString *const kIDToken = @"idToken";
  38. /** @var kCaptchaResponseKey
  39. @brief The key for the "captchaResponse" value in the request.
  40. */
  41. static NSString *const kCaptchaResponseKey = @"captchaResponse";
  42. /** @var kClientType
  43. @brief The key for the "clientType" value in the request.
  44. */
  45. static NSString *const kClientType = @"clientType";
  46. /** @var kRecaptchaVersion
  47. @brief The key for the "recaptchaVersion" value in the request.
  48. */
  49. static NSString *const kRecaptchaVersion = @"recaptchaVersion";
  50. /** @var kReturnSecureTokenKey
  51. @brief The key for the "returnSecureToken" value in the request.
  52. */
  53. static NSString *const kReturnSecureTokenKey = @"returnSecureToken";
  54. /** @var kTenantIDKey
  55. @brief The key for the tenant id value in the request.
  56. */
  57. static NSString *const kTenantIDKey = @"tenantId";
  58. @implementation FIRSignUpNewUserRequest
  59. - (nullable instancetype)initWithEmail:(nullable NSString *)email
  60. password:(nullable NSString *)password
  61. displayName:(nullable NSString *)displayName
  62. idToken:(nullable NSString *)idToken
  63. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  64. self = [super initWithEndpoint:kSignupNewUserEndpoint requestConfiguration:requestConfiguration];
  65. if (self) {
  66. _email = [email copy];
  67. _password = [password copy];
  68. _displayName = [displayName copy];
  69. _idToken = [idToken copy];
  70. _returnSecureToken = YES;
  71. }
  72. return self;
  73. }
  74. - (nullable instancetype)initWithRequestConfiguration:
  75. (FIRAuthRequestConfiguration *)requestConfiguration {
  76. self = [self initWithEmail:nil
  77. password:nil
  78. displayName:nil
  79. idToken:nil
  80. requestConfiguration:requestConfiguration];
  81. return self;
  82. }
  83. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
  84. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  85. if (_email) {
  86. postBody[kEmailKey] = _email;
  87. }
  88. if (_password) {
  89. postBody[kPasswordKey] = _password;
  90. }
  91. if (_displayName) {
  92. postBody[kDisplayNameKey] = _displayName;
  93. }
  94. if (_idToken) {
  95. postBody[kIDToken] = _idToken;
  96. }
  97. if (_captchaResponse) {
  98. postBody[kCaptchaResponseKey] = _captchaResponse;
  99. }
  100. if (self.clientType) {
  101. postBody[kClientType] = self.clientType;
  102. }
  103. if (_recaptchaVersion) {
  104. postBody[kRecaptchaVersion] = _recaptchaVersion;
  105. }
  106. if (_returnSecureToken) {
  107. postBody[kReturnSecureTokenKey] = @YES;
  108. }
  109. if (self.tenantID) {
  110. postBody[kTenantIDKey] = self.tenantID;
  111. }
  112. return [postBody copy];
  113. }
  114. - (void)injectRecaptchaFields:(NSString *_Nullable)recaptchaResponse
  115. recaptchaVersion:(NSString *)recaptchaVersion {
  116. _captchaResponse = recaptchaResponse;
  117. _recaptchaVersion = recaptchaVersion;
  118. }
  119. @end
  120. NS_ASSUME_NONNULL_END