FIRStartMFAEnrollmentRequest.m 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. self.useIdentityPlatform = YES;
  31. if (self) {
  32. _IDToken = IDToken;
  33. _phoneEnrollmentInfo = phoneEnrollmentInfo;
  34. }
  35. return self;
  36. }
  37. - (nullable instancetype)initWithIDToken:(NSString *)IDToken
  38. TOTPEnrollmentInfo:
  39. (FIRAuthProtoStartMFATOTPEnrollmentRequestInfo *)TOTPEnrollmentInfo
  40. requestConfiguration:(FIRAuthRequestConfiguration *)requestConfiguration {
  41. self = [super initWithEndpoint:kStartMFAEnrollmentEndPoint
  42. requestConfiguration:requestConfiguration];
  43. self.useIdentityPlatform = YES;
  44. if (self) {
  45. _IDToken = IDToken;
  46. _TOTPEnrollmentInfo = TOTPEnrollmentInfo;
  47. }
  48. return self;
  49. }
  50. - (nullable id)unencodedHTTPRequestBodyWithError:(NSError *__autoreleasing _Nullable *)error {
  51. NSMutableDictionary *postBody = [NSMutableDictionary dictionary];
  52. if (_IDToken) {
  53. postBody[@"idToken"] = _IDToken;
  54. }
  55. if (_phoneEnrollmentInfo) {
  56. postBody[@"phoneEnrollmentInfo"] = [_phoneEnrollmentInfo dictionary];
  57. } else if (_TOTPEnrollmentInfo) {
  58. postBody[@"totpEnrollmentInfo"] = [_TOTPEnrollmentInfo dictionary];
  59. }
  60. if (self.tenantID) {
  61. postBody[kTenantIDKey] = self.tenantID;
  62. }
  63. return [postBody copy];
  64. }
  65. @end