FIRVerifyPhoneNumberRequest.m 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 "FIRVerifyPhoneNumberRequest.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. /** @var kVerifyPhoneNumberEndPoint
  19. @brief The "verifyPhoneNumber" endpoint.
  20. */
  21. static NSString *const kVerifyPhoneNumberEndPoint = @"verifyPhoneNumber";
  22. /** @var kVerificationIDKey
  23. @brief The key for the verification ID parameter in the request.
  24. */
  25. static NSString *const kVerificationIDKey = @"sessionInfo";
  26. /** @var kVerificationCodeKey
  27. @brief The key for the verification code parameter in the request.
  28. */
  29. static NSString *const kVerificationCodeKey = @"code";
  30. /** @var kIDTokenKey
  31. @brief The key for the "ID Token" value in the request.
  32. */
  33. static NSString *const kIDTokenKey = @"idToken";
  34. /** @var kTemporaryProofKey
  35. @brief The key for the temporary proof value in the request.
  36. */
  37. static NSString *const kTemporaryProofKey = @"temporaryProof";
  38. /** @var kPhoneNumberKey
  39. @brief The key for the phone number value in the request.
  40. */
  41. static NSString *const kPhoneNumberKey = @"phoneNumber";
  42. @implementation FIRVerifyPhoneNumberRequest
  43. - (nullable instancetype)initWithTemporaryProof:(NSString *)temporaryProof
  44. phoneNumber:(NSString *)phoneNumber
  45. APIKey:(NSString *)APIKey {
  46. self = [super initWithEndpoint:kVerifyPhoneNumberEndPoint APIKey:APIKey];
  47. if (self) {
  48. _temporaryProof = [temporaryProof copy];
  49. _phoneNumber = [phoneNumber copy];
  50. }
  51. return self;
  52. }
  53. - (nullable instancetype)initWithVerificationID:(NSString *)verificationID
  54. verificationCode:(NSString *)verificationCode
  55. APIKey:(NSString *)APIKey {
  56. self = [super initWithEndpoint:kVerifyPhoneNumberEndPoint APIKey:APIKey];
  57. if (self) {
  58. _verificationID = verificationID;
  59. _verificationCode = verificationCode;
  60. }
  61. return self;
  62. }
  63. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Nullable *)error {
  64. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  65. if (_verificationID) {
  66. postBody[kVerificationIDKey] = _verificationID;
  67. }
  68. if (_verificationCode) {
  69. postBody[kVerificationCodeKey] = _verificationCode;
  70. }
  71. if (_accessToken) {
  72. postBody[kIDTokenKey] = _accessToken;
  73. }
  74. if (_temporaryProof) {
  75. postBody[kTemporaryProofKey] = _temporaryProof;
  76. }
  77. if (_phoneNumber) {
  78. postBody[kPhoneNumberKey] = _phoneNumber;
  79. }
  80. return postBody;
  81. }
  82. @end
  83. NS_ASSUME_NONNULL_END