VerifyPasswordRequest.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. /** @var kVerifyPasswordEndpoint
  16. @brief The "verifyPassword" endpoint.
  17. */
  18. private let kVerifyPasswordEndpoint = "verifyPassword"
  19. /** @var kEmailKey
  20. @brief The key for the "email" value in the request.
  21. */
  22. private let kEmailKey = "email"
  23. /** @var kPasswordKey
  24. @brief The key for the "password" value in the request.
  25. */
  26. private let kPasswordKey = "password"
  27. /** @var kPendingIDTokenKey
  28. @brief The key for the "pendingIdToken" value in the request.
  29. */
  30. private let kPendingIDTokenKey = "pendingIdToken"
  31. /** @var kCaptchaChallengeKey
  32. @brief The key for the "captchaChallenge" value in the request.
  33. */
  34. private let kCaptchaChallengeKey = "captchaChallenge"
  35. /** @var kCaptchaResponseKey
  36. @brief The key for the "captchaResponse" value in the request.
  37. */
  38. private let kCaptchaResponseKey = "captchaResponse"
  39. /** @var kReturnSecureTokenKey
  40. @brief The key for the "returnSecureToken" value in the request.
  41. */
  42. private let kReturnSecureTokenKey = "returnSecureToken"
  43. /** @var kTenantIDKey
  44. @brief The key for the tenant id value in the request.
  45. */
  46. private let kTenantIDKey = "tenantId"
  47. /** @class FIRVerifyPasswordRequest
  48. @brief Represents the parameters for the verifyPassword endpoint.
  49. @see https://developers.google.com/identity/toolkit/web/reference/relyingparty/verifyPassword
  50. */
  51. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  52. @objc(FIRVerifyPasswordRequest) public class VerifyPasswordRequest: IdentityToolkitRequest,
  53. AuthRPCRequest {
  54. /** @property email
  55. @brief The email of the user.
  56. */
  57. @objc public var email: String
  58. /** @property password
  59. @brief The password inputed by the user.
  60. */
  61. @objc public var password: String
  62. /** @property pendingIDToken
  63. @brief The GITKit token for the non-trusted IDP, which is to be confirmed by the user.
  64. */
  65. @objc public var pendingIDToken: String?
  66. /** @property captchaChallenge
  67. @brief The captcha challenge.
  68. */
  69. @objc public var captchaChallenge: String?
  70. /** @property captchaResponse
  71. @brief Response to the captcha.
  72. */
  73. @objc public var captchaResponse: String?
  74. /** @property returnSecureToken
  75. @brief Whether the response should return access token and refresh token directly.
  76. @remarks The default value is @c YES .
  77. */
  78. @objc public var returnSecureToken: Bool
  79. /** @var response
  80. @brief The corresponding response for this request
  81. */
  82. @objc public var response: AuthRPCResponse = VerifyPasswordResponse()
  83. @objc public init(email: String, password: String,
  84. requestConfiguration: AuthRequestConfiguration) {
  85. self.email = email
  86. self.password = password
  87. returnSecureToken = true
  88. super.init(endpoint: kVerifyPasswordEndpoint, requestConfiguration: requestConfiguration)
  89. }
  90. public func unencodedHTTPRequestBody() throws -> [String: AnyHashable] {
  91. var body: [String: AnyHashable] = [
  92. kEmailKey: email,
  93. kPasswordKey: password,
  94. ]
  95. if let pendingIDToken = pendingIDToken {
  96. body[kPendingIDTokenKey] = pendingIDToken
  97. }
  98. if let captchaChallenge = captchaChallenge {
  99. body[kCaptchaChallengeKey] = captchaChallenge
  100. }
  101. if let captchaResponse = captchaResponse {
  102. body[kCaptchaResponseKey] = captchaResponse
  103. }
  104. if returnSecureToken {
  105. body[kReturnSecureTokenKey] = true
  106. }
  107. if let tenantID = tenantID {
  108. body[kTenantIDKey] = tenantID
  109. }
  110. return body
  111. }
  112. }