FIRStartMFAEnrollmentRequest.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/FIRStartMFAEnrollmentRequest.h"
  17. #import "FirebaseAuth/Sources/Backend/RPC/Proto/Phone/FIRAuthProtoStartMFAPhoneRequestInfo.h"
  18. #import "FirebaseAuth/Sources/Backend/RPC/Proto/TOTP/FIRAuthProtoStartMFATOTPEnrollmentRequestInfo.h"
  19. static NSString *const kStartMFAEnrollmentEndPoint = @"accounts/mfaEnrollment:start";
  20. /** @var kTenantIDKey
  21. @brief The key for the tenant id value in the request.
  22. */
  23. static NSString *const kTenantIDKey = @"tenantId";
  24. @implementation FIRStartMFAEnrollmentRequest
  25. - (nullable instancetype)initWithIDToken:(NSString *)IDToken
  26. enrollmentInfo:(FIRAuthProtoStartMFAPhoneRequestInfo *)phoneEnrollmentInfo
  27. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  28. self = [super initWithEndpoint:kStartMFAEnrollmentEndPoint
  29. requestConfiguration:requestConfiguration
  30. useIdentityPlatform:YES
  31. useStaging:NO];
  32. if (self) {
  33. _IDToken = IDToken;
  34. _phoneEnrollmentInfo = phoneEnrollmentInfo;
  35. }
  36. return self;
  37. }
  38. - (nullable instancetype)initWithIDToken:(NSString *)IDToken
  39. TOTPEnrollmentInfo:
  40. (FIRAuthProtoStartMFATOTPEnrollmentRequestInfo *)TOTPEnrollmentInfo
  41. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  42. self = [super initWithEndpoint:kStartMFAEnrollmentEndPoint
  43. requestConfiguration:requestConfiguration
  44. useIdentityPlatform:YES
  45. useStaging:NO];
  46. if (self) {
  47. _IDToken = IDToken;
  48. _TOTPEnrollmentInfo = TOTPEnrollmentInfo;
  49. }
  50. return self;
  51. }
  52. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Nullable *)error {
  53. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  54. if (_IDToken) {
  55. postBody[@"idToken"] = _IDToken;
  56. }
  57. if (_phoneEnrollmentInfo) {
  58. postBody[@"phoneEnrollmentInfo"] = [_phoneEnrollmentInfo dictionary];
  59. } else if (_TOTPEnrollmentInfo) {
  60. postBody[@"totpEnrollmentInfo"] = [_TOTPEnrollmentInfo dictionary];
  61. }
  62. if (self.tenantID) {
  63. postBody[kTenantIDKey] = self.tenantID;
  64. }
  65. return [postBody copy];
  66. }
  67. @end