Esempio n. 1
0
 /**
  * Sign the request using OAuth. This uses the consumer token and key
  *
  * @param string $method the method (get/put/delete/post)
  * @param string $url the url to sign (http://site/social/rest/people/1/@me)
  * @param array $params the params that should be appended to the url (count=20 fields=foo, etc)
  * @param string $postBody for POST/PUT requests, the postBody is included in the signature
  * @return string the signed url
  */
 public function sign(apiHttpRequest $request)
 {
     // add the developer key to the request before signing it
     if ($this->developerKey) {
         $request->setUrl($request->getUrl() . (strpos($request->getUrl(), '?') === false ? '?' : '&') . 'key=' . urlencode($this->developerKey));
     }
     // and sign the request
     $oauthRequest = apiClientOAuthRequest::from_request($request->getMethod(), $request->getBaseUrl(), $request->getQueryParams());
     $params = $this->mergeParameters($request->getQueryParams());
     foreach ($params as $key => $val) {
         if (is_array($val)) {
             $val = implode(',', $val);
         }
         $oauthRequest->set_parameter($key, $val);
     }
     $oauthRequest->sign_request($this->signatureMethod, $this->consumerToken, $this->accessToken);
     $authHeaders = $oauthRequest->to_header();
     $headers = $request->getHeaders();
     $headers[] = $authHeaders;
     $request->setHeaders($headers);
     // and add the access token key to it (since it doesn't include the secret, it's still secure to store this in cache)
     $request->accessKey = $this->accessToken->key;
     return $request;
 }
 /**
  * Sign the request using OAuth. This uses the consumer token and key
  *
  * @param string $method the method (get/put/delete/post)
  * @param string $url the url to sign (http://site/social/rest/people/1/@me)
  * @param array $params the params that should be appended to the url (count=20 fields=foo, etc)
  * @param string $postBody for POST/PUT requests, the postBody is included in the signature
  * @return string the signed url
  */
 public function sign(apiHttpRequest $request)
 {
     // add the developer key to the request before signing it
     if ($this->developerKey) {
         $url = $request->getUrl();
         $url .= (strpos($url, '?') === false ? '?' : '&') . 'key=' . urlencode($this->developerKey);
     }
     // and sign the request
     $oauthRequest = OAuthRequest::from_request($request->getMethod(), $request->getBaseUrl(), $request->getQueryParams());
     $params = $this->mergeParameters($request->getQueryParams());
     foreach ($params as $key => $val) {
         if (is_array($val)) {
             $val = implode(',', $val);
         }
         $oauthRequest->set_parameter($key, $val);
     }
     $oauthRequest->sign_request($this->signatureMethod, $this->consumerToken, $this->accessToken);
     $signedUrl = $oauthRequest->to_url();
     // Set an originalUrl property that can be used to cache the resource
     $request->originalUrl = $request->getUrl();
     // and add the access token key to it (since it doesn't include the secret, it's still secure to store this in cache)
     $request->accessKey = $this->accessToken->key;
     $request->setUrl($signedUrl);
     return $request;
 }