FIRVerifyPasswordRequest.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "FIRVerifyPasswordRequest.h"
  17. /** @var kVerifyPasswordEndpoint
  18. @brief The "verifyPassword" endpoint.
  19. */
  20. static NSString *const kVerifyPasswordEndpoint = @"verifyPassword";
  21. /** @var kEmailKey
  22. @brief The key for the "email" value in the request.
  23. */
  24. static NSString *const kEmailKey = @"email";
  25. /** @var kPasswordKey
  26. @brief The key for the "password" value in the request.
  27. */
  28. static NSString *const kPasswordKey = @"password";
  29. /** @var kPendingIDTokenKey
  30. @brief The key for the "pendingIdToken" value in the request.
  31. */
  32. static NSString *const kPendingIDTokenKey = @"pendingIdToken";
  33. /** @var kCaptchaChallengeKey
  34. @brief The key for the "captchaChallenge" value in the request.
  35. */
  36. static NSString *const kCaptchaChallengeKey = @"captchaChallenge";
  37. /** @var kCaptchaResponseKey
  38. @brief The key for the "captchaResponse" value in the request.
  39. */
  40. static NSString *const kCaptchaResponseKey = @"captchaResponse";
  41. /** @var kReturnSecureTokenKey
  42. @brief The key for the "returnSecureToken" value in the request.
  43. */
  44. static NSString *const kReturnSecureTokenKey = @"returnSecureToken";
  45. @implementation FIRVerifyPasswordRequest
  46. - (nullable instancetype)initWithEmail:(NSString *)email
  47. password:(NSString *)password
  48. APIKey:(NSString *)APIKey {
  49. self = [super initWithEndpoint:kVerifyPasswordEndpoint APIKey:APIKey];
  50. if (self) {
  51. _email = [email copy];
  52. _password = [password copy];
  53. _returnSecureToken = YES;
  54. }
  55. return self;
  56. }
  57. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
  58. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  59. if (_email) {
  60. postBody[kEmailKey] = _email;
  61. }
  62. if (_password) {
  63. postBody[kPasswordKey] = _password;
  64. }
  65. if (_pendingIDToken) {
  66. postBody[kPendingIDTokenKey] = _pendingIDToken;
  67. }
  68. if (_captchaChallenge) {
  69. postBody[kCaptchaChallengeKey] = _captchaChallenge;
  70. }
  71. if (_captchaResponse) {
  72. postBody[kCaptchaResponseKey] = _captchaResponse;
  73. }
  74. if (_returnSecureToken) {
  75. postBody[kReturnSecureTokenKey] = @YES;
  76. }
  77. return postBody;
  78. }
  79. @end