本文整理汇总了PHP中Zend_Oauth_Http_Utility::sign方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Oauth_Http_Utility::sign方法的具体用法?PHP Zend_Oauth_Http_Utility::sign怎么用?PHP Zend_Oauth_Http_Utility::sign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Oauth_Http_Utility
的用法示例。
在下文中一共展示了Zend_Oauth_Http_Utility::sign方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _validateSignature
/**
* Validate signature
*
* @throws Mage_Oauth_Exception
*/
protected function _validateSignature()
{
$util = new Zend_Oauth_Http_Utility();
$calculatedSign = $util->sign(array_merge($this->_params, $this->_protocolParams), $this->_protocolParams['oauth_signature_method'], $this->_consumer->getSecret(), $this->_token->getSecret(), $this->_request->getMethod(), $this->_request->getScheme() . '://' . $this->_request->getHttpHost() . $this->_request->getRequestUri());
if ($calculatedSign != $this->_protocolParams['oauth_signature']) {
$this->_throwException('', self::ERR_SIGNATURE_INVALID);
}
}
示例2: checkOAuthRequest
/**
* Validate OAuth request
* @param Zend_Uri_Http $url Request URL, will use current if null
* @param array $params Additional parameters
* @return bool
* @throws Zend_Oauth_Exception
*/
public function checkOAuthRequest(Zend_Uri_Http $url = null, $params = array())
{
if (empty($url)) {
$this->url = $this->getRequestUrl();
} else {
$this->url = clone $url;
}
// We'll ignore query for the pruposes of URL matching
$this->url->setQuery('');
if (isset($_SERVER['REQUEST_METHOD'])) {
$method = $_SERVER['REQUEST_METHOD'];
} elseif (isset($_SERVER['HTTP_METHOD'])) {
$method = $_SERVER['HTTP_METHOD'];
} else {
$method = 'GET';
}
$params = $this->assembleParams($method, $params);
$this->checkSignatureMethod($params['oauth_signature_method']);
$this->checkRequiredParams($params);
$this->timestamp = $params['oauth_timestamp'];
$this->nonce = $params['oauth_nonce'];
$this->consumer_key = $params['oauth_consumer_key'];
if (!is_callable($this->nonceHandler)) {
throw new Zend_Oauth_Exception("Nonce handler not callable", self::BAD_NONCE);
}
$res = call_user_func($this->nonceHandler, $this);
if ($res != self::OK) {
throw new Zend_Oauth_Exception("Invalid request", $res);
}
if (!is_callable($this->consumerHandler)) {
throw new Zend_Oauth_Exception("Consumer handler not callable", self::CONSUMER_KEY_UNKNOWN);
}
$res = call_user_func($this->consumerHandler, $this);
// this will set $this->consumer_secret if OK
if ($res != self::OK) {
throw new Zend_Oauth_Exception("Consumer key invalid", $res);
}
if ($this->needsToken()) {
$this->token = $params['oauth_token'];
$this->verifier = $params['oauth_verifier'];
if (!is_callable($this->tokenHandler)) {
throw new Zend_Oauth_Exception("Token handler not callable", self::TOKEN_REJECTED);
}
$res = call_user_func($this->tokenHandler, $this);
// this will set $this->token_secret if OK
if ($res != self::OK) {
throw new Zend_Oauth_Exception("Token invalid", $res);
}
}
$util = new Zend_Oauth_Http_Utility();
$req_sign = $params['oauth_signature'];
unset($params['oauth_signature']);
$our_sign = $util->sign($params, $params['oauth_signature_method'], $this->consumer_secret, $this->token_secret, $method, $this->url->getUri());
if ($req_sign != $our_sign) {
// TODO: think how to extract signature base string
$this->problem = $our_sign;
throw new Zend_Oauth_Exception("Invalid signature", self::INVALID_SIGNATURE);
}
return true;
}
示例3: request
/**
* Send a request
* @param String $method Methodname
* @param Array $queryParams GET parameters
* @return Array
*/
public function request($method, array $queryParams)
{
$queryParams['format'] = self::RESPONSE_FORMAT;
if (!substr($method, 0, 5) != 'vimeo') {
$method = 'vimeo.' . $method;
}
$queryParams['method'] = $method;
$queryString = http_build_query($queryParams);
$url = self::VIMEO_API_URL . '?' . $queryString;
$oAuthHttpUtility = new Zend_Oauth_Http_Utility();
$params = array('oauth_consumer_key' => $this->getConsumerKey(), 'oauth_nonce' => $oAuthHttpUtility->generateNonce(), 'oauth_timestamp' => $oAuthHttpUtility->generateTimestamp(), 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_version' => '1.0');
if ($this->getAccessToken()) {
$params['oauth_token'] = $this->getAccessToken();
}
$params['oauth_signature'] = $oAuthHttpUtility->sign(array_merge($queryParams, $params), 'HMAC-SHA1', $this->getConsumerSecret(), $this->getAccessTokenSecret(), Zend_Oauth::GET, self::VIMEO_API_URL);
$httpClient = $this->getHttpClient()->setHeaders('Authorization', $oAuthHttpUtility->toAuthorizationHeader($params))->setMethod(Zend_Http_Client::GET)->setUri($url);
$response = $httpClient->request()->getBody();
$response = json_decode($response, true);
if ($response['stat'] == 'fail') {
$error = 'An unknown error occurred at Vimeo.';
if (!empty($response['err']['expl'])) {
$error = $response['err']['expl'];
}
throw new Garp_Service_Vimeo_Exception($response['err']['expl']);
}
return $response;
}