FIRSignUpNewUserRequest.m 3.8 KB

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