FIRFinalizeMFAEnrollmentRequest.m 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. self.useIdentityPlatform = YES;
  32. if (self) {
  33. _IDToken = IDToken;
  34. _displayName = displayName;
  35. _phoneVerificationInfo = phoneVerificationInfo;
  36. }
  37. return self;
  38. }
  39. - (nullable instancetype)initWithIDToken:(NSString *)IDToken
  40. displayName:(NSString *)displayName
  41. TOTPVerificationInfo:
  42. (FIRAuthProtoFinalizeMFATOTPEnrollmentRequestInfo *)TOTPVerificationInfo
  43. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  44. self = [super initWithEndpoint:kFinalizeMFAEnrollmentEndPoint
  45. requestConfiguration:requestConfiguration];
  46. self.useIdentityPlatform = YES;
  47. if (self) {
  48. _IDToken = IDToken;
  49. _displayName = displayName;
  50. _TOTPVerificationInfo = TOTPVerificationInfo;
  51. }
  52. return self;
  53. }
  54. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Nullable *)error {
  55. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  56. if (_IDToken) {
  57. postBody[@"idToken"] = _IDToken;
  58. }
  59. if (_displayName) {
  60. postBody[@"displayName"] = _displayName;
  61. }
  62. if (_phoneVerificationInfo) {
  63. postBody[@"phoneVerificationInfo"] = [_phoneVerificationInfo dictionary];
  64. } else if (_TOTPVerificationInfo) {
  65. postBody[@"totpVerificationInfo"] = [_TOTPVerificationInfo dictionary];
  66. }
  67. if (self.tenantID) {
  68. postBody[kTenantIDKey] = self.tenantID;
  69. }
  70. return [postBody copy];
  71. }
  72. @end
  73. NS_ASSUME_NONNULL_END