FIRFinalizeMFAEnrollmentRequest.m 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright 2019 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/LICENSE2.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/MultiFactor/Enroll/FIRFinalizeMFAEnrollmentRequest.h"
  17. NS_ASSUME_NONNULL_BEGIN
  18. static NSString *const kFinalizeMFAEnrollmentEndPoint = @"accounts/mfaEnrollment:finalize";
  19. /** @var kTenantIDKey
  20. @brief The key for the tenant id value in the request.
  21. */
  22. static NSString *const kTenantIDKey = @"tenantId";
  23. @implementation FIRFinalizeMFAEnrollmentRequest
  24. - (nullable instancetype)initWithIDToken:(NSString *)IDToken
  25. displayName:(NSString *)displayName
  26. phoneVerificationInfo:
  27. (FIRAuthProtoFinalizeMFAPhoneRequestInfo *)phoneVerificationInfo
  28. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  29. self = [super initWithEndpoint:kFinalizeMFAEnrollmentEndPoint
  30. requestConfiguration:requestConfiguration
  31. useIdentityPlatform:YES
  32. useStaging:NO];
  33. if (self) {
  34. _IDToken = IDToken;
  35. _displayName = displayName;
  36. _phoneVerificationInfo = phoneVerificationInfo;
  37. }
  38. return self;
  39. }
  40. - (nullable instancetype)initWithIDToken:(NSString *)IDToken
  41. displayName:(NSString *)displayName
  42. TOTPVerificationInfo:
  43. (FIRAuthProtoFinalizeMFATOTPEnrollmentRequestInfo *)TOTPVerificationInfo
  44. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  45. self = [super initWithEndpoint:kFinalizeMFAEnrollmentEndPoint
  46. requestConfiguration:requestConfiguration
  47. useIdentityPlatform:YES
  48. useStaging:NO];
  49. if (self) {
  50. _IDToken = IDToken;
  51. _displayName = displayName;
  52. _TOTPVerificationInfo = TOTPVerificationInfo;
  53. }
  54. return self;
  55. }
  56. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Nullable *)error {
  57. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  58. if (_IDToken) {
  59. postBody[@"idToken"] = _IDToken;
  60. }
  61. if (_displayName) {
  62. postBody[@"displayName"] = _displayName;
  63. }
  64. if (_phoneVerificationInfo) {
  65. postBody[@"phoneVerificationInfo"] = [_phoneVerificationInfo dictionary];
  66. } else if (_TOTPVerificationInfo) {
  67. postBody[@"totpVerificationInfo"] = [_TOTPVerificationInfo dictionary];
  68. }
  69. if (self.tenantID) {
  70. postBody[kTenantIDKey] = self.tenantID;
  71. }
  72. return [postBody copy];
  73. }
  74. @end
  75. NS_ASSUME_NONNULL_END