FIRResetPasswordRequest.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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/FIRResetPasswordRequest.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. /** @var kResetPasswordEndpoint
  19. @brief The "resetPassword" endpoint.
  20. */
  21. static NSString *const kResetPasswordEndpoint = @"resetPassword";
  22. /** @var kOOBCodeKey
  23. @brief The "resetPassword" key.
  24. */
  25. static NSString *const kOOBCodeKey = @"oobCode";
  26. /** @var kCurrentPasswordKey
  27. @brief The "newPassword" key.
  28. */
  29. static NSString *const kCurrentPasswordKey = @"newPassword";
  30. /** @var kTenantIDKey
  31. @brief The key for the tenant id value in the request.
  32. */
  33. static NSString *const kTenantIDKey = @"tenantId";
  34. @implementation FIRResetPasswordRequest
  35. - (nullable instancetype)initWithOobCode:(NSString *)oobCode
  36. newPassword:(nullable NSString *)newPassword
  37. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  38. self = [super initWithEndpoint:kResetPasswordEndpoint requestConfiguration:requestConfiguration];
  39. if (self) {
  40. _oobCode = oobCode;
  41. _updatedPassword = newPassword;
  42. }
  43. return self;
  44. }
  45. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
  46. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  47. postBody[kOOBCodeKey] = _oobCode;
  48. if (_updatedPassword) {
  49. postBody[kCurrentPasswordKey] = _updatedPassword;
  50. }
  51. if (self.tenantID) {
  52. postBody[kTenantIDKey] = self.tenantID;
  53. }
  54. return [postBody copy];
  55. }
  56. @end
  57. NS_ASSUME_NONNULL_END