VerifyCustomTokenRequest.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 kVerifyCustomTokenEndpoint
  16. @brief The "verifyPassword" endpoint.
  17. */
  18. private let kVerifyCustomTokenEndpoint = "verifyCustomToken"
  19. /** @var kTokenKey
  20. @brief The key for the "token" value in the request.
  21. */
  22. private let kTokenKey = "token"
  23. /** @var kReturnSecureTokenKey
  24. @brief The key for the "returnSecureToken" value in the request.
  25. */
  26. private let kReturnSecureTokenKey = "returnSecureToken"
  27. /** @var kTenantIDKey
  28. @brief The key for the tenant id value in the request.
  29. */
  30. private let kTenantIDKey = "tenantId"
  31. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  32. @objc(FIRVerifyCustomTokenRequest) public class VerifyCustomTokenRequest: IdentityToolkitRequest,
  33. AuthRPCRequest {
  34. @objc public let token: String
  35. @objc public var returnSecureToken: Bool
  36. /** @var response
  37. @brief The corresponding response for this request
  38. */
  39. @objc public var response: AuthRPCResponse = VerifyCustomTokenResponse()
  40. @objc public init(token: String, requestConfiguration: AuthRequestConfiguration) {
  41. self.token = token
  42. returnSecureToken = true
  43. super.init(endpoint: kVerifyCustomTokenEndpoint, requestConfiguration: requestConfiguration)
  44. }
  45. public func unencodedHTTPRequestBody() throws -> [String: AnyHashable] {
  46. var postBody: [String: AnyHashable] = [
  47. kTokenKey: token,
  48. ]
  49. if returnSecureToken {
  50. postBody[kReturnSecureTokenKey] = true
  51. }
  52. if let tenantID = tenantID {
  53. postBody[kTenantIDKey] = tenantID
  54. }
  55. return postBody
  56. }
  57. }