FinalizeMFAEnrollmentRequest.swift 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 kFinalizeMFAEnrollmentEndPoint = "accounts/mfaEnrollment: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 FinalizeMFAEnrollmentRequest: IdentityToolkitRequest, AuthRPCRequest {
  20. typealias Response = FinalizeMFAEnrollmentResponse
  21. let idToken: String?
  22. let displayName: String?
  23. var phoneVerificationInfo: AuthProtoFinalizeMFAPhoneRequestInfo?
  24. var totpVerificationInfo: AuthProtoFinalizeMFATOTPEnrollmentRequestInfo?
  25. init(idToken: String?, displayName: String?,
  26. phoneVerificationInfo: AuthProtoFinalizeMFAPhoneRequestInfo?,
  27. requestConfiguration: AuthRequestConfiguration) {
  28. self.idToken = idToken
  29. self.displayName = displayName
  30. self.phoneVerificationInfo = phoneVerificationInfo
  31. super.init(
  32. endpoint: kFinalizeMFAEnrollmentEndPoint,
  33. requestConfiguration: requestConfiguration,
  34. useIdentityPlatform: true
  35. )
  36. }
  37. init(idToken: String?, displayName: String?,
  38. totpVerificationInfo: AuthProtoFinalizeMFATOTPEnrollmentRequestInfo?,
  39. requestConfiguration: AuthRequestConfiguration) {
  40. self.idToken = idToken
  41. self.displayName = displayName
  42. self.totpVerificationInfo = totpVerificationInfo
  43. super.init(
  44. endpoint: kFinalizeMFAEnrollmentEndPoint,
  45. requestConfiguration: requestConfiguration,
  46. useIdentityPlatform: true
  47. )
  48. }
  49. func unencodedHTTPRequestBody() throws -> [String: AnyHashable] {
  50. var body: [String: AnyHashable] = [:]
  51. if let idToken = idToken {
  52. body["idToken"] = idToken
  53. }
  54. if let displayName = displayName {
  55. body["displayName"] = displayName
  56. }
  57. if let phoneVerificationInfo {
  58. body["phoneVerificationInfo"] = phoneVerificationInfo.dictionary
  59. } else if let totpVerificationInfo {
  60. body["totpVerificationInfo"] = totpVerificationInfo.dictionary
  61. }
  62. if let tenantID = tenantID {
  63. body[kTenantIDKey] = tenantID
  64. }
  65. return body
  66. }
  67. }