FIRSendVerificationCodeRequest.m 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/FIRSendVerificationCodeRequest.h"
  17. #import "FirebaseAuth/Sources/SystemService/FIRAuthAppCredential.h"
  18. NS_ASSUME_NONNULL_BEGIN
  19. /** @var kSendVerificationCodeEndPoint
  20. @brief The "sendVerificationCodeEnd" endpoint.
  21. */
  22. static NSString *const kSendVerificationCodeEndPoint = @"sendVerificationCode";
  23. /** @var kPhoneNumberKey
  24. @brief The key for the Phone Number parameter in the request.
  25. */
  26. static NSString *const kPhoneNumberKey = @"phoneNumber";
  27. /** @var kReceiptKey
  28. @brief The key for the receipt parameter in the request.
  29. */
  30. static NSString *const kReceiptKey = @"iosReceipt";
  31. /** @var kSecretKey
  32. @brief The key for the Secret parameter in the request.
  33. */
  34. static NSString *const kSecretKey = @"iosSecret";
  35. /** @var kreCAPTCHATokenKey
  36. @brief The key for the reCAPTCHAToken parameter in the request.
  37. */
  38. static NSString *const kreCAPTCHATokenKey = @"recaptchaToken";
  39. /** @var kTenantIDKey
  40. @brief The key for the tenant id value in the request.
  41. */
  42. static NSString *const kTenantIDKey = @"tenantId";
  43. @implementation FIRSendVerificationCodeRequest {
  44. }
  45. - (nullable instancetype)initWithPhoneNumber:(NSString *)phoneNumber
  46. appCredential:(nullable FIRAuthAppCredential *)appCredential
  47. reCAPTCHAToken:(nullable NSString *)reCAPTCHAToken
  48. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  49. self = [super initWithEndpoint:kSendVerificationCodeEndPoint
  50. requestConfiguration:requestConfiguration];
  51. if (self) {
  52. _phoneNumber = [phoneNumber copy];
  53. _appCredential = appCredential;
  54. _reCAPTCHAToken = [reCAPTCHAToken copy];
  55. }
  56. return self;
  57. }
  58. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
  59. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  60. if (_phoneNumber) {
  61. postBody[kPhoneNumberKey] = _phoneNumber;
  62. }
  63. if (_appCredential.receipt) {
  64. postBody[kReceiptKey] = _appCredential.receipt;
  65. }
  66. if (_appCredential.secret) {
  67. postBody[kSecretKey] = _appCredential.secret;
  68. }
  69. if (_reCAPTCHAToken) {
  70. postBody[kreCAPTCHATokenKey] = _reCAPTCHAToken;
  71. }
  72. if (self.tenantID) {
  73. postBody[kTenantIDKey] = self.tenantID;
  74. }
  75. return [postBody copy];
  76. }
  77. @end
  78. NS_ASSUME_NONNULL_END