GetRecaptchaConfigRequest.swift 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. /** @var kRequestTypeKey
  18. @brief The name of the required "requestType" property in the request.
  19. */
  20. private let kRequestTypeKey = "requestType"
  21. /** @var kEmailKey
  22. @brief The name of the "email" property in the request.
  23. */
  24. private let kEmailKey = "email"
  25. /** @var kNewEmailKey
  26. @brief The name of the "newEmail" property in the request.
  27. */
  28. private let kNewEmailKey = "newEmail"
  29. /** @var kIDTokenKey
  30. @brief The key for the "idToken" value in the request. This is actually the STS Access Token,
  31. despite it's confusing (backwards compatiable) parameter name.
  32. */
  33. private let kIDTokenKey = "idToken"
  34. /** @var kGetRecaptchaConfigEndpoint
  35. @brief The "getRecaptchaConfig" endpoint.
  36. */
  37. private let kGetRecaptchaConfigEndpoint = "recaptchaConfig"
  38. /** @var kClientType
  39. @brief The key for the "clientType" value in the request.
  40. */
  41. private let kClientTypeKey = "clientType"
  42. /** @var kVersionKey
  43. @brief The key for the "version" value in the request.
  44. */
  45. private let kVersionKey = "version"
  46. /** @var kTenantIDKey
  47. @brief The key for the tenant id value in the request.
  48. */
  49. private let kTenantIDKey = "tenantId"
  50. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  51. class GetRecaptchaConfigRequest: IdentityToolkitRequest, AuthRPCRequest {
  52. typealias Response = GetRecaptchaConfigResponse
  53. required init(requestConfiguration: AuthRequestConfiguration) {
  54. requestConfiguration.httpMethod = "GET"
  55. super.init(
  56. endpoint: kGetRecaptchaConfigEndpoint,
  57. requestConfiguration: requestConfiguration,
  58. useIdentityPlatform: true
  59. )
  60. }
  61. func unencodedHTTPRequestBody() throws -> [String: AnyHashable] {
  62. return [:]
  63. }
  64. override func containsPostBody() -> Bool {
  65. false
  66. }
  67. override func queryParams() -> String {
  68. var queryParams = "&\(kClientTypeKey)=\(clientType)&\(kVersionKey)=\(kRecaptchaVersion)"
  69. if let tenantID {
  70. queryParams += "&\(kTenantIDKey)=\(tenantID)"
  71. }
  72. return queryParams
  73. }
  74. }