GetRecaptchaConfigRequest.swift 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 kRecaptchaVersion = "RECAPTCHA_ENTERPRISE"
  16. private let kGetOobConfirmationCodeEndpoint = "getOobConfirmationCode"
  17. /// The name of the required "requestType" property in the request.
  18. private let kRequestTypeKey = "requestType"
  19. /// The name of the "email" property in the request.
  20. private let kEmailKey = "email"
  21. /// The name of the "newEmail" property in the request.
  22. private let kNewEmailKey = "newEmail"
  23. /// The key for the "idToken" value in the request. This is actually the STS Access Token,
  24. /// despite its confusing (backwards compatible) parameter name.
  25. private let kIDTokenKey = "idToken"
  26. /// The "getRecaptchaConfig" endpoint.
  27. private let kGetRecaptchaConfigEndpoint = "recaptchaConfig"
  28. /// The key for the "clientType" value in the request.
  29. private let kClientTypeKey = "clientType"
  30. /// The key for the "version" value in the request.
  31. private let kVersionKey = "version"
  32. /// The key for the tenant id value in the request.
  33. private let kTenantIDKey = "tenantId"
  34. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  35. class GetRecaptchaConfigRequest: IdentityToolkitRequest, AuthRPCRequest {
  36. typealias Response = GetRecaptchaConfigResponse
  37. required init(requestConfiguration: AuthRequestConfiguration) {
  38. super.init(
  39. endpoint: kGetRecaptchaConfigEndpoint,
  40. requestConfiguration: requestConfiguration,
  41. useIdentityPlatform: true
  42. )
  43. }
  44. var unencodedHTTPRequestBody: [String: AnyHashable]? {
  45. nil
  46. }
  47. override func queryParams() -> String {
  48. var queryParams = "&\(kClientTypeKey)=\(clientType)&\(kVersionKey)=\(kRecaptchaVersion)"
  49. if let tenantID {
  50. queryParams += "&\(kTenantIDKey)=\(tenantID)"
  51. }
  52. return queryParams
  53. }
  54. }