Returns the request authentication headers when a client ID and shared secret are provided.

@param string $url
@param array  $parameters

@return array
500799
private function getRequestHeaders($url, array $parameters)
    {
        $headers = array();

        if (isset($this->clientId) && isset($this->sharedSecret)) {
            $objectIdentifier = null;
            if ($this->apiVersion === '1.1' && isset($parameters['id'])) {
                $objectIdentifier = $parameters['id'];
            } elseif ($this->apiVersion === '1.0' && isset($parameters['api_id'])) {
                $objectIdentifier = $parameters['api_id'];
            }

            $headers['X-Tulip-Client-ID'] = $this->clientId;
            $headers['X-Tulip-Client-Authentication'] = hash_hmac('sha256', $this->clientId.$url.$objectIdentifier, $this->sharedSecret);
        }

        return $headers;
    }
83614
protected function prepareRequest($url, array $headers, array $parameters, $method, array $settings)
    {
        $includeCallback = (isset($settings['includeCallback'])) ? $settings['includeCallback'] : false;
        $includeVerifier = (isset($settings['includeVerifier'])) ? $settings['includeVerifier'] : false;

        //Set OAuth parameters/headers
        if ($this->isOauth1()) {
            //OAuth 1.0
            $this->log('making request using OAuth1.0a spec');

            //Get standard OAuth headers
            $oAuthHeaders = $this->getOauthHeaders($includeCallback);

            if ($includeVerifier && isset($_GET['oauth_verifier'])) {
                $oAuthHeaders['oauth_verifier'] = $_GET['oauth_verifier'];

                if ($this->_debug) {
                    $_SESSION['oauth']['debug']['oauth_verifier'] = $_GET['oauth_verifier'];
                }
            }

            //Add the parameters
            $oAuthHeaders                    = array_merge($oAuthHeaders, $parameters);
            $base_info                       = $this->buildBaseString($url, $method, $oAuthHeaders);
            $composite_key                   = $this->getCompositeKey();
            $oAuthHeaders['oauth_signature'] = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
            $headers[]                       = $this->buildAuthorizationHeader($oAuthHeaders);
            $headers[]                       = 'Expect:';

            if ($this->_debug) {
                $_SESSION['oauth']['debug']['basestring'] = $base_info;
                $_SESSION['oauth']['debug']['headers']    = $headers;
            }
        } else {
            //OAuth 2.0
            $this->log('making request using OAuth2 spec');

            $parameters['access_token'] = $this->_access_token;
        }

        return array($headers, $parameters);
    }
112185
protected function sign(array $parameters)
    {
        //turn into string and add the secret key to the end
        $signatureString = '';

        foreach ($parameters as $key => $value) {
            $signatureString .= $key . '=' . $value;
        }

        $signatureString .= $this->secret;

        return sha1($signatureString);
    }
624698
public function get($uri, array $parameters = array(), $requestHeaders = array()) {
        try {
            return $this->executeGet($uri, $parameters, $requestHeaders);
        } catch (Unauthenticated $e) {
            $this->auth_token->reset();
            return $this->executeGet($uri, $parameters, $requestHeaders);
        }
    }
1187826
protected function postRequest($url, $parameters = [])
    {
        if (!empty($parameters)) {
            $this->parameters->addPost($parameters);
        }

        return $this->request($url);
    }
1295664
public function get($url, $params=array(), $token='', $secret='') {
        return $this->request('GET', $url, $params, $token, $secret);
    }
337527
protected function request($url, $parameters = array(), $request = false)
        {
            $this->lastRequest = $url;
            $this->lastRequestData = $parameters;
            $this->responseHeaders = array();

            $curl = curl_init($url);

            $curlOptions = array(
                CURLOPT_SSL_VERIFYPEER => false,
                CURLOPT_REFERER        => $url,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_HEADERFUNCTION => array($this, 'parseHeader'),
            );

            if (! empty($parameters) || ! empty($request)) {
                if (! empty($request)) {
                    $curlOptions[ CURLOPT_CUSTOMREQUEST ] = $request;
                    $parameters = http_build_query($parameters);
                } else {
                    $curlOptions[ CURLOPT_POST ] = true;
                }

                $curlOptions[ CURLOPT_POSTFIELDS ] = $parameters;
            }

            curl_setopt_array($curl, $curlOptions);

            $response = curl_exec($curl);
            $error    = curl_error($curl);

            $this->lastRequestInfo = curl_getinfo($curl);

            curl_close($curl);

            if (! empty($error)) {
                throw new \Exception($error);
            }

            return $this->parseResponse($response);
        }
877949
public function get($uri, $parameters = array())
    {
        return $this->request(self::METHOD_GET, $this->getUrl($uri), $parameters);
    }
1091177
private function get_credentials( $url ) {
		$headers      = parse_url( $url );
		$type         = $this->get_class_vars( 'Base', 'caller' );
		$username_key = null;
		$password_key = null;
		$credentials  = [
			'username'      => null,
			'password'      => null,
			'api.wordpress' => 'api.wordpress.org' === $headers['host'],
			'isset'         => false,
			'private'       => false,
		];
		$hosts        = [ 'bitbucket.org', 'api.bitbucket.org' ];

		$repos = array_merge(
			Singleton::get_instance( 'Plugin', $this )->get_plugin_configs(),
			Singleton::get_instance( 'Theme', $this )->get_theme_configs()
		);

		$slug = isset( $_REQUEST['slug'] ) ? $_REQUEST['slug'] : false;
		$slug = ! $slug && isset( $_REQUEST['plugin'] ) ? $_REQUEST['plugin'] : $slug;
		$slug = ! $slug && isset( $_REQUEST['theme'] ) ? $_REQUEST['theme'] : $slug;

		// Set for bulk upgrade.
		if ( ! $slug ) {
			$plugins     = isset( $_REQUEST['plugins'] )
				? array_map( 'dirname', explode( ',', $_REQUEST['plugins'] ) )
				: [];
			$themes      = isset( $_REQUEST['themes'] )
				? explode( ',', $_REQUEST['themes'] )
				: [];
			$bulk_update = array_merge( $plugins, $themes );
			if ( ! empty( $bulk_update ) ) {
				$slug = array_filter(
					$bulk_update,
					function ( $e ) use ( $url ) {
						return false !== strpos( $url, $e );
					}
				);
				$slug = array_pop( $slug );
			}
		}

		$type = $slug &&
				isset( $repos[ $slug ] ) && property_exists( $repos[ $slug ], 'git' )
			? $repos[ $slug ]->git
			: $type;

		// Set for WP-CLI.
		if ( ! $slug ) {
			foreach ( $repos as $repo ) {
				if ( property_exists( $repo, 'download_link' ) && $url === $repo->download_link ) {
					$type = $repo->git;
					break;
				}
			}
		}

		// Set for Remote Install.
		$type = isset( $_POST['github_updater_api'], $_POST['github_updater_repo'] ) &&
				false !== strpos( $url, basename( $_POST['github_updater_repo'] ) )
			? $_POST['github_updater_api']
			: $type;

		switch ( $type ) {
			case 'bitbucket':
			case $type instanceof Bitbucket_API:
			case $type instanceof Bitbucket_Server_API:
				$bitbucket_org = in_array( $headers['host'], $hosts, true );
				$username_key  = $bitbucket_org ? 'bitbucket_username' : 'bitbucket_server_username';
				$password_key  = $bitbucket_org ? 'bitbucket_password' : 'bitbucket_server_password';
				break;
		}

		// TODO: can use `( $this->caller )::$options` in PHP7.
		$caller          = $this->get_class_vars( 'Base', 'caller' );
		static::$options = $caller instanceof Install ? $caller::$options : static::$options;

		if ( isset( static::$options[ $username_key ], static::$options[ $password_key ] ) ) {
			$credentials['username'] = static::$options[ $username_key ];
			$credentials['password'] = static::$options[ $password_key ];
			$credentials['isset']    = true;
			$credentials['private']  = $this->is_repo_private( $url );
		}

		return $credentials;
	}
97040
public function getAuthorizeUrl(array $params = [])
    {
        $result = $this->OAuthRequest(self::API_BASE . self::REQUEST_PATH, $params);

        if ($result->getCode() == 200) {
            $tokens = $this->parseResponse($result->getResponse());

            return [
                'auth_url' => self::API_BASE . $this->auth_method . '?oauth_token=' . $tokens['oauth_token'],
                'secret'   => $tokens['oauth_token_secret'],
                'token'    => $tokens['oauth_token']
            ];

        }

        return $this->handleError($result);
    }
206613
public static function normalize(string $url, array $parameters = []):string
    {
        $normalizedUrl = $url;
        if (!empty($parameters)) {
            $normalizedUrl .= (false !== strpos($url, '?') ? '&' : '?') . http_build_query($parameters, '', '&');
        }
        return $normalizedUrl;
    }
853393
protected static function prepareRequest($url, $parameters = [], $headers = [])
    {
        $request = curl_init();

        if ($query = http_build_query($parameters)) {
            $url .= '?'.$query;
        }

        curl_setopt($request, CURLOPT_URL, $url);
        curl_setopt($request, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($request, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($request, CURLINFO_HEADER_OUT, true);
        curl_setopt($request, CURLOPT_SSL_VERIFYPEER, true);

        return $request;
    }
717272
protected function request($method, $url, $parameters = array())
    {
        Logger::get()->debug('HTTP: starting request...');
        $headers = $this->headers;

        // Add accepted content type header.
        $headers[] = 'Content-Type: ' . $this->contentType;
        $headers[] = 'Accept: ' . $this->acceptedContentType;

        $handler = curl_init();

        if (!is_null($this->user)) {
            curl_setopt($handler, CURLOPT_USERPWD, $this->user . ':' . $this->password);
        }

        Logger::get()->debug('HTTP: method is ' . $method);
        switch ($method) {
            case self::METHOD_DELETE:
                curl_setopt($handler, CURLOPT_URL, $url . '?' . http_build_query($parameters));
                curl_setopt($handler, CURLOPT_CUSTOMREQUEST, self::DELETE);
                break;
            case self::METHOD_POST:
                curl_setopt($handler, CURLOPT_URL, $url);
                curl_setopt($handler, CURLOPT_POST, true);
                curl_setopt($handler, CURLOPT_POSTFIELDS, $parameters);
                break;
            case self::METHOD_GET:
                curl_setopt($handler, CURLOPT_URL, $url . '?' . http_build_query($parameters));
                break;
        }

        curl_setopt($handler, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($handler, CURLOPT_HTTPHEADER, $headers);
        Logger::get()->debug('HTTP: headers set.');

        // Send the request to the server.
        Logger::get()->debug("HTTP: requesting $url...");
        $output = curl_exec($handler);
        $errNo = curl_errno($handler);
        $error = curl_error($handler);
        // Obtain the status.
        Logger::get()->debug('HTTP: Done. Getting status...');
        $status = curl_getinfo($handler, CURLINFO_HTTP_CODE);
        // The handler is no longer needed.
        curl_close($handler);
        Logger::get()->debug('HTTP: request finished.');

        if ($errNo) {
            throw new Exception('HTTP: cURL failed: ' . $error, $errNo);
        }

        // If cURL had no errors itself, then there is an HTTP response.
        switch ($status) {
            case self::STATUS_OK:
            case self::STATUS_CREATED:
            case self::STATUS_ACCEPTED:
            case self::STATUS_NO_CONTENT:
                return $output;
            default:
                throw new Http\Exception("HTTP {$status}", $status);
        }
    }
635098
private static function parametersToHeaders($parameters)
    {
        $filtered = array_filter(array_keys($parameters), function ($key) {
            return strpos($key, 'HTTP_') === 0;
        });
        $transformKey = function ($key) {
            $parts = explode('_', $key);
            $lowerCase = array_map('strtolower', array_slice($parts, 1));
            $firstUpper = array_map('ucfirst', $lowerCase);
            return implode('-', $firstUpper);
        };

        return array_reduce($filtered, function ($acc, $key) use ($parameters, $transformKey) {
            $headerKey = $transformKey($key);

            return array_merge(
                $acc,
                [$headerKey => $parameters[$key]]
            );
        }, []);
    }
752187
private function requestAuthTokens(array $payload, string $url): array
    {
        $headers = [
            'Content-Type' => self::CONTENT_TYPE,
        ];
        $options = [
            'headers' => $headers,
            'json' => $payload,
        ];

        $response = $this->client->request(
            'POST',
            $url,
            $options
        );

        return json_decode((string) $response->getBody(), true);
    }
629063
public static function listAllCashOnDeliveryPaymentsAsync(array $parameters = [])
    {
        return self::listAllCashOnDeliveryPaymentsAsyncWithHttpInfo($page, $size, $sort)
            ->then(
                function ($response) {
                    return $response[0];
                }
            );
    }
719870
protected function _oauthRequest($url, $params) {
    if (!isset($params['access_token'])) {
      $params['access_token'] = $this->getAccessToken();
    }

    if (isset($params['access_token'])) {
      $params['appsecret_proof'] = $this->getAppSecretProof($params['access_token']);
    }

    // json_encode all params values that are not strings
    foreach ($params as $key => $value) {
      if (!is_string($value) && !($value instanceof CURLFile)) {
        $params[$key] = json_encode($value);
      }
    }

    return $this->makeRequest($url, $params);
  }