FIRVerifyPhoneNumberRequest.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. requestConfiguration:
  46. (FIRAuthRequestConfiguration *)requestConfiguration {
  47. self = [super initWithEndpoint:kVerifyPhoneNumberEndPoint
  48. requestConfiguration:requestConfiguration];
  49. if (self) {
  50. _temporaryProof = [temporaryProof copy];
  51. _phoneNumber = [phoneNumber copy];
  52. }
  53. return self;
  54. }
  55. - (nullable instancetype)initWithVerificationID:(NSString *)verificationID
  56. verificationCode:(NSString *)verificationCode
  57. requestConfiguration:
  58. (FIRAuthRequestConfiguration *)requestConfiguration {
  59. self = [super initWithEndpoint:kVerifyPhoneNumberEndPoint
  60. requestConfiguration:requestConfiguration];
  61. if (self) {
  62. _verificationID = verificationID;
  63. _verificationCode = verificationCode;
  64. }
  65. return self;
  66. }
  67. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Nullable *)error {
  68. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  69. if (_verificationID) {
  70. postBody[kVerificationIDKey] = _verificationID;
  71. }
  72. if (_verificationCode) {
  73. postBody[kVerificationCodeKey] = _verificationCode;
  74. }
  75. if (_accessToken) {
  76. postBody[kIDTokenKey] = _accessToken;
  77. }
  78. if (_temporaryProof) {
  79. postBody[kTemporaryProofKey] = _temporaryProof;
  80. }
  81. if (_phoneNumber) {
  82. postBody[kPhoneNumberKey] = _phoneNumber;
  83. }
  84. return postBody;
  85. }
  86. @end
  87. NS_ASSUME_NONNULL_END