/** * Builds the authorization header for an authenticated API request * @param string $method * @param UriInterface $uri the uri the request is headed * @param \OAuth\OAuth1\Token\TokenInterface $token * @param $bodyParams Request body if applicable (key/value pairs) * @return string */ protected function buildAuthorizationHeaderForAPIRequest($method, UriInterface $uri, TokenInterface $token, $bodyParams = null) { $this->signature->setTokenSecret($token->getAccessTokenSecret()); $parameters = $this->getBasicAuthorizationHeaderInfo(); if (isset($parameters['oauth_callback'])) { unset($parameters['oauth_callback']); } $parameters = array_merge($parameters, array('oauth_token' => $token->getAccessToken())); $mergedParams = is_array($bodyParams) ? array_merge($parameters, $bodyParams) : $parameters; $parameters['oauth_signature'] = $this->signature->getSignature($uri, $mergedParams, $method); $authorizationHeader = 'OAuth '; $delimiter = ''; foreach ($parameters as $key => $value) { $authorizationHeader .= $delimiter . rawurlencode($key) . '="' . rawurlencode($value) . '"'; $delimiter = ', '; } return $authorizationHeader; }