FIRSignUpNewUserRequest.m 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 kReturnSecureTokenKey
  35. @brief The key for the "returnSecureToken" value in the request.
  36. */
  37. static NSString *const kReturnSecureTokenKey = @"returnSecureToken";
  38. /** @var kTenantIDKey
  39. @brief The key for the tenant id value in the request.
  40. */
  41. static NSString *const kTenantIDKey = @"tenantId";
  42. @implementation FIRSignUpNewUserRequest
  43. - (nullable instancetype)initWithEmail:(nullable NSString *)email
  44. password:(nullable NSString *)password
  45. displayName:(nullable NSString *)displayName
  46. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  47. self = [super initWithEndpoint:kSignupNewUserEndpoint requestConfiguration:requestConfiguration];
  48. if (self) {
  49. _email = [email copy];
  50. _password = [password copy];
  51. _displayName = [displayName copy];
  52. _returnSecureToken = YES;
  53. }
  54. return self;
  55. }
  56. - (nullable instancetype)initWithRequestConfiguration:
  57. (FIRAuthRequestConfiguration *)requestConfiguration {
  58. self = [self initWithEmail:nil
  59. password:nil
  60. displayName:nil
  61. requestConfiguration:requestConfiguration];
  62. return self;
  63. }
  64. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
  65. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  66. if (_email) {
  67. postBody[kEmailKey] = _email;
  68. }
  69. if (_password) {
  70. postBody[kPasswordKey] = _password;
  71. }
  72. if (_displayName) {
  73. postBody[kDisplayNameKey] = _displayName;
  74. }
  75. if (_returnSecureToken) {
  76. postBody[kReturnSecureTokenKey] = @YES;
  77. }
  78. if (self.tenantID) {
  79. postBody[kTenantIDKey] = self.tenantID;
  80. }
  81. return [postBody copy];
  82. }
  83. @end
  84. NS_ASSUME_NONNULL_END