def authcode_grant(authcode_uri, callback_query)
    ac_params = Util.decode_form(URI.parse(authcode_uri).query)
    unless ac_params['state'] && ac_params['redirect_uri']
      raise ArgumentError, "authcode redirect must happen before authcode grant"
    end
    begin
      params = Util.decode_form(callback_query)
      authcode = params['code']
      raise BadResponse unless params['state'] == ac_params['state'] && authcode
    rescue URI::InvalidURIError, ArgumentError, BadResponse
      raise BadResponse, "received invalid response from target #{@target}"
    end
    request_token(:grant_type => 'authorization_code', :code => authcode,
        :redirect_uri => ac_params['redirect_uri'])
  end
def authcode_grant(authcode_uri, callback_query)
    ac_params = Util.decode_form(URI.parse(authcode_uri).query)
    unless ac_params['state'] && ac_params['redirect_uri']
      raise ArgumentError, "authcode redirect must happen before authcode grant"
    end
    begin
      params = Util.decode_form(callback_query)
      authcode = params['code']
      raise BadResponse unless params['state'] == ac_params['state'] && authcode
    rescue URI::InvalidURIError, ArgumentError, BadResponse
      raise BadResponse, "received invalid response from target #{@target}"
    end
    request_token(:grant_type => 'authorization_code', :code => authcode,
        :redirect_uri => ac_params['redirect_uri'])
  end
Uses the instance client credentials in addition to +callback_query+
 to get a token via the authorization code grant.
 @param [String] authcode_uri must be from a previous call to {#authcode_uri}
   and contains state used to validate the contents of the reply from the
   server.
 @param [String] callback_query must be the query portion of the URL
   received by the client after the user's browser is redirected back from
   the server. It contains the authorization code.
 @see http://tools.ietf.org/html/rfc6749#section-4.1
 @return [TokenInfo]