FIRSendVerificationCodeRequest.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 "FIRSendVerificationCodeRequest.h"
  17. #import "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. @implementation FIRSendVerificationCodeRequest {
  36. }
  37. - (nullable instancetype)initWithPhoneNumber:(NSString *)phoneNumber
  38. appCredential:(FIRAuthAppCredential *)appCredential
  39. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  40. self = [super initWithEndpoint:kSendVerificationCodeEndPoint
  41. requestConfiguration:requestConfiguration];
  42. if (self) {
  43. _phoneNumber = [phoneNumber copy];
  44. _appCredential = appCredential;
  45. }
  46. return self;
  47. }
  48. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *_Nullable *_Nullable)error {
  49. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  50. if (_phoneNumber) {
  51. postBody[kPhoneNumberKey] = _phoneNumber;
  52. }
  53. if (_appCredential.receipt) {
  54. postBody[kReceiptKey] = _appCredential.receipt;
  55. }
  56. if (_appCredential.secret) {
  57. postBody[kSecretKey] = _appCredential.secret;
  58. }
  59. return postBody;
  60. }
  61. @end
  62. NS_ASSUME_NONNULL_END