GetAccountInfoRequest.swift 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. /// The "getAccountInfo" endpoint.
  16. private let kGetAccountInfoEndpoint = "getAccountInfo"
  17. /// The key for the "idToken" value in the request. This is actually the STS Access Token,
  18. /// despite its confusing (backwards compatible) parameter name.
  19. private let kIDTokenKey = "idToken"
  20. /// Represents the parameters for the getAccountInfo endpoint.
  21. /// See https://developers.google.com/identity/toolkit/web/reference/relyingparty/getAccountInfo
  22. @available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
  23. class GetAccountInfoRequest: IdentityToolkitRequest, AuthRPCRequest {
  24. typealias Response = GetAccountInfoResponse
  25. /// The STS Access Token for the authenticated user.
  26. let accessToken: String
  27. /// Designated initializer.
  28. /// - Parameter accessToken: The Access Token of the authenticated user.
  29. /// - Parameter requestConfiguration: An object containing configurations to be added to the
  30. /// request.
  31. init(accessToken: String, requestConfiguration: AuthRequestConfiguration) {
  32. self.accessToken = accessToken
  33. super.init(endpoint: kGetAccountInfoEndpoint, requestConfiguration: requestConfiguration)
  34. }
  35. func unencodedHTTPRequestBody() throws -> [String: AnyHashable] {
  36. return [kIDTokenKey: accessToken]
  37. }
  38. }