OAuthSimple::signatures PHP Method

signatures() public method

Set the signatures (as well as validate the ones you have)
public signatures ( $signatures ) : OAuthSimple
$signatures (object) object/hash of the token/signature pairs {api_key:, shared_secret:, oauth_token: oauth_secret:}
return OAuthSimple
    public function signatures($signatures)
    {
        if (!empty($signatures) && !is_array($signatures)) {
            throw new OAuthSimpleException('Must pass dictionary array to OAuthSimple.signatures');
        }
        if (!empty($signatures)) {
            if (empty($this->_secrets)) {
                $this->_secrets = array();
            }
            $this->_secrets = array_merge($this->_secrets, $signatures);
        }
        if (isset($this->_secrets['api_key'])) {
            $this->_secrets['consumer_key'] = $this->_secrets['api_key'];
        }
        if (isset($this->_secrets['access_token'])) {
            $this->_secrets['oauth_token'] = $this->_secrets['access_token'];
        }
        if (isset($this->_secrets['access_secret'])) {
            $this->_secrets['shared_secret'] = $this->_secrets['access_secret'];
        }
        if (isset($this->_secrets['oauth_token_secret'])) {
            $this->_secrets['oauth_secret'] = $this->_secrets['oauth_token_secret'];
        }
        if (empty($this->_secrets['consumer_key'])) {
            throw new OAuthSimpleException('Missing required consumer_key in OAuthSimple.signatures');
        }
        if (empty($this->_secrets['shared_secret'])) {
            throw new OAuthSimpleException('Missing requires shared_secret in OAuthSimple.signatures');
        }
        if (!empty($this->_secrets['oauth_token']) && empty($this->_secrets['oauth_secret'])) {
            throw new OAuthSimpleException('Missing oauth_secret for supplied oauth_token in OAuthSimple.signatures');
        }
        return $this;
    }

Usage Example

Esempio n. 1
0
 /**
  * Обертка для отправки подписанного запроса через curl
  *
  * @param $url
  * @param string $method
  * @param array $data - POST данные
  * @param $opts - доп. параметры для curl
  * @return mixed
  */
 public function doCurl($url, $method = "POST", $data = array(), $opts = array())
 {
     $ch = curl_init($url);
     $opts += array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_HEADER => 0, CURLOPT_SSL_VERIFYPEER => 0, CURLOPT_SSL_VERIFYHOST => 0);
     if ($method == "POST") {
         $opts[CURLOPT_POST] = TRUE;
         $opts[CURLOPT_POSTFIELDS] = http_build_query($data);
     }
     $oauth = new OAuthSimple($this->app_key, $this->app_secret);
     if (!$this->request_token && $this->token) {
         $this->request_token = $this->token;
     }
     if ($this->request_token) {
         $oauth->setParameters(array('oauth_token' => $this->request_token['oauth_token']));
         $oauth->signatures(array('oauth_secret' => $this->request_token['oauth_token_secret']));
     }
     if ($method == "POST" && count($data)) {
         $oauth->setParameters(http_build_query($data));
     }
     $path = $url;
     $query = strrchr($url, '?');
     if (!empty($query)) {
         $oauth->setParameters(substr($query, 1));
         $path = substr($url, 0, -strlen($query));
     }
     $signed = $oauth->sign(array('action' => $method, 'path' => $path));
     $opts[CURLOPT_HTTPHEADER][] = "Authorization: " . $signed['header'];
     if ($method == "PUT") {
         $opts[CURLOPT_CUSTOMREQUEST] = "PUT";
     }
     curl_setopt_array($ch, $opts);
     $result = curl_exec($ch);
     return $result;
 }
All Usage Examples Of OAuthSimple::signatures