class Google::Auth::OAuth2::STSClient

def exchange_token options = {}

Returns:
  • (Hash) - A hash containing the token exchange response.

Parameters:
  • additional_headers (Hash) -- :
  • requested_token_type (String) --
  • scopes (Array) --
  • audience (String) --
  • resource (String) --
  • subject_token_type (String) --
  • subject_token (String) --
  • grant_type (String) --
  • connection (Faraday instance) --
def exchange_token options = {}
  missing_required_opts = [:grant_type, :subject_token, :subject_token_type] - options.keys
  unless missing_required_opts.empty?
    raise ArgumentError, "Missing required options: #{missing_required_opts.join ', '}"
  end
  # TODO: Add the ability to add authentication to the headers
  headers = URLENCODED_HEADERS.dup.merge(options[:additional_headers] || {})
  request_body = make_request options
  response = connection.post @token_exchange_endpoint, URI.encode_www_form(request_body), headers
  if response.status != 200
    raise "Token exchange failed with status #{response.status}"
  end
  MultiJson.load response.body
end