FIRStartMFAEnrollmentRequest.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. static NSString *const kStartMFAEnrollmentEndPoint = @"accounts/mfaEnrollment:start";
  19. /** @var kTenantIDKey
  20. @brief The key for the tenant id value in the request.
  21. */
  22. static NSString *const kTenantIDKey = @"tenantId";
  23. @implementation FIRStartMFAEnrollmentRequest
  24. - (nullable instancetype)initWithIDToken:(NSString *)IDToken
  25. enrollmentInfo:(FIRAuthProtoStartMFAPhoneRequestInfo *)enrollmentInfo
  26. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  27. self = [super initWithEndpoint:kStartMFAEnrollmentEndPoint
  28. requestConfiguration:requestConfiguration];
  29. self.useIdentityPlatform = YES;
  30. if (self) {
  31. _IDToken = IDToken;
  32. _enrollmentInfo = enrollmentInfo;
  33. }
  34. return self;
  35. }
  36. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Nullable *)error {
  37. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  38. if (_IDToken) {
  39. postBody[@"idToken"] = _IDToken;
  40. }
  41. if (_enrollmentInfo) {
  42. if ([_enrollmentInfo isKindOfClass:[FIRAuthProtoStartMFAPhoneRequestInfo class]]) {
  43. postBody[@"phoneEnrollmentInfo"] = [_enrollmentInfo dictionary];
  44. }
  45. }
  46. if (self.tenantID) {
  47. postBody[kTenantIDKey] = self.tenantID;
  48. }
  49. return [postBody copy];
  50. }
  51. @end