VerifyCustomTokenRequest.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. class VerifyCustomTokenRequest: IdentityToolkitRequest, AuthRPCRequest {
  33. typealias Response = VerifyCustomTokenResponse
  34. let token: String
  35. var returnSecureToken: Bool
  36. init(token: String, requestConfiguration: AuthRequestConfiguration) {
  37. self.token = token
  38. returnSecureToken = true
  39. super.init(endpoint: kVerifyCustomTokenEndpoint, requestConfiguration: requestConfiguration)
  40. }
  41. func unencodedHTTPRequestBody() throws -> [String: AnyHashable] {
  42. var postBody: [String: AnyHashable] = [
  43. kTokenKey: token,
  44. ]
  45. if returnSecureToken {
  46. postBody[kReturnSecureTokenKey] = true
  47. }
  48. if let tenantID = tenantID {
  49. postBody[kTenantIDKey] = tenantID
  50. }
  51. return postBody
  52. }
  53. }