FinalizeMFASignInRequest.swift 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 kFinalizeMFASignInEndPoint = "accounts/mfaSignIn:finalize"
  16. /// The key for the tenant id value in the request.
  17. private let kTenantIDKey = "tenantId"
  18. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  19. class FinalizeMFASignInRequest: IdentityToolkitRequest, AuthRPCRequest {
  20. typealias Response = FinalizeMFAEnrollmentResponse
  21. var mfaPendingCredential: String?
  22. var verificationInfo: AuthProto?
  23. init(mfaPendingCredential: String?,
  24. verificationInfo: AuthProto?,
  25. requestConfiguration: AuthRequestConfiguration) {
  26. self.mfaPendingCredential = mfaPendingCredential
  27. self.verificationInfo = verificationInfo
  28. super.init(endpoint: kFinalizeMFASignInEndPoint,
  29. requestConfiguration: requestConfiguration,
  30. useIdentityPlatform: true)
  31. }
  32. func unencodedHTTPRequestBody() throws -> [String: AnyHashable] {
  33. var body: [String: AnyHashable] = [:]
  34. if let mfaPendingCredential = mfaPendingCredential {
  35. body["mfaPendingCredential"] = mfaPendingCredential
  36. }
  37. if let verificationInfo = verificationInfo as? AuthProtoFinalizeMFAPhoneRequestInfo {
  38. body["phoneVerificationInfo"] = verificationInfo.dictionary
  39. }
  40. if let verificationInfo = verificationInfo as? AuthProtoFinalizeMFATOTPSignInRequestInfo {
  41. body["totpVerificationInfo"] = verificationInfo.dictionary
  42. // mfaEnrollmentID only required for TOTP
  43. body["mfaEnrollmentId"] = verificationInfo.mfaEnrollmentID
  44. }
  45. if let tenantID = tenantID {
  46. body[kTenantIDKey] = tenantID
  47. }
  48. return body
  49. }
  50. }