StartMFASignInRequest.swift 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import Foundation
  15. private let kStartMFASignInEndPoint = "accounts/mfaSignIn:start"
  16. /** @var kTenantIDKey
  17. @brief The key for the tenant id value in the request.
  18. */
  19. private let kTenantIDKey = "tenantId"
  20. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  21. @objc(FIRStartMFASignInRequest) public class StartMFASignInRequest: IdentityToolkitRequest,
  22. AuthRPCRequest {
  23. var MFAPendingCredential: String?
  24. var MFAEnrollmentID: String?
  25. var signInInfo: AuthProtoStartMFAPhoneRequestInfo?
  26. /** @var response
  27. @brief The corresponding response for this request
  28. */
  29. @objc public var response: AuthRPCResponse = StartMFASignInResponse()
  30. init(MFAPendingCredential: String?, MFAEnrollmentID: String?,
  31. signInInfo: AuthProtoStartMFAPhoneRequestInfo?,
  32. requestConfiguration: AuthRequestConfiguration) {
  33. self.MFAPendingCredential = MFAPendingCredential
  34. self.MFAEnrollmentID = MFAEnrollmentID
  35. self.signInInfo = signInInfo
  36. super.init(
  37. endpoint: kStartMFASignInEndPoint,
  38. requestConfiguration: requestConfiguration,
  39. useIdentityPlatform: true,
  40. useStaging: false
  41. )
  42. }
  43. public func unencodedHTTPRequestBody() throws -> [String: AnyHashable] {
  44. var body: [String: AnyHashable] = [:]
  45. if let MFAPendingCredential = MFAPendingCredential {
  46. body["mfaPendingCredential"] = MFAPendingCredential
  47. }
  48. if let MFAEnrollmentID = MFAEnrollmentID {
  49. body["mfaEnrollmentId"] = MFAEnrollmentID
  50. }
  51. if let signInInfo = signInInfo {
  52. body["phoneSignInInfo"] = signInInfo.dictionary
  53. }
  54. if let tenantID = tenantID {
  55. body[kTenantIDKey] = tenantID
  56. }
  57. return body
  58. }
  59. }