本文整理汇总了PHP中Zend_Oauth_Http_Utility类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Oauth_Http_Utility类的具体用法?PHP Zend_Oauth_Http_Utility怎么用?PHP Zend_Oauth_Http_Utility使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Oauth_Http_Utility类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getBaseSignatureString
/**
* Get base signature string
*
* @param array $params
* @param null|string $method
* @param null|string $url
* @return string
*/
protected function _getBaseSignatureString(array $params, $method = null, $url = null)
{
$encodedParams = array();
foreach ($params as $key => $value) {
$encodedParams[Zend_Oauth_Http_Utility::urlEncode($key)] = Zend_Oauth_Http_Utility::urlEncode($value);
}
$baseStrings = array();
if (isset($method)) {
$baseStrings[] = strtoupper($method);
}
if (isset($url)) {
// should normalise later
$baseStrings[] = Zend_Oauth_Http_Utility::urlEncode($this->normaliseBaseSignatureUrl($url));
}
if (isset($encodedParams['oauth_signature'])) {
unset($encodedParams['oauth_signature']);
}
$baseStrings[] = Zend_Oauth_Http_Utility::urlEncode($this->_toByteValueOrderedQueryString($encodedParams));
return implode('&', $baseStrings);
}
示例2: testUrlEncodeCorrectlyEncodesU3001
public function testUrlEncodeCorrectlyEncodesU3001()
{
$string = '、';
$this->assertEquals('%E3%80%81', Zend_Oauth_Http_Utility::urlEncode($string));
}
示例3: _toAuthorizationHeader
/**
* Generates a valid OAuth Authorization header based on the provided
* parameters and realm.
*
* @param array $params
* @param string $realm
* @return string
*/
protected function _toAuthorizationHeader(array $params, $realm = null)
{
$headerValue = array();
$headerValue[] = 'OAuth realm="' . $realm . '"';
foreach ($params as $key => $value) {
if (!preg_match("/^oauth_/", $key)) {
continue;
}
$headerValue[] = Zend_Oauth_Http_Utility::urlEncode($key) . '="' . Zend_Oauth_Http_Utility::urlEncode($value) . '"';
}
return implode(",", $headerValue);
}
示例4: _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);
}
}
示例5: getOauthHeader
/**
* Get OAuth 'Authentication' header string
*
* @return string
*/
public function getOauthHeader()
{
$this->_oauthParams['oauth_timestamp'] = time();
$this->_oauthParams['oauth_nonce'] = md5(uniqid(rand(), true));
// http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/drafts/5/spec.html
// Haven't fully implemented that spec, but the idea is the same.
// TODO: The server should validate this hash to be more secure
$this->_oauthParams['oauth_body_hash'] = $this->_getRequestHash();
$this->_generateOauthSignature('POST');
$headerValue = array();
foreach ($this->_oauthParams as $key => $value) {
$headerValue[] = Zend_Oauth_Http_Utility::urlEncode($key) . '="' . Zend_Oauth_Http_Utility::urlEncode($value) . '"';
}
return implode(",", $headerValue);
}
示例6: 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;
}
示例7: array
require_once 'Zend/Oauth.php';
require_once 'Zend/Oauth/Config.php';
require_once 'Zend/Oauth/Token/Access.php';
require_once 'Zend/Mail/Protocol/Imap.php';
require_once 'Zend/Mail/Storage/Imap.php';
/**
* Setup OAuth
*/
$options = array('requestScheme' => Zend_Oauth::REQUEST_SCHEME_HEADER, 'version' => '1.0', 'signatureMethod' => 'HMAC-SHA1', 'consumerKey' => $TWO_LEGGED_CONSUMER_KEY, 'consumerSecret' => $TWO_LEGGED_CONSUMER_SECRET_HMAC);
$config = new Zend_Oauth_Config();
$config->setOptions($options);
$config->setToken(new Zend_Oauth_Token_Access());
$config->setRequestMethod('GET');
$url = 'https://mail.google.com/mail/b/' . $TWO_LEGGED_EMAIL_ADDRESS . '/imap/';
$urlWithXoauth = $url . '?xoauth_requestor_id=' . urlencode($TWO_LEGGED_EMAIL_ADDRESS);
$httpUtility = new Zend_Oauth_Http_Utility();
/**
* Get an unsorted array of oauth params,
* including the signature based off those params.
*/
$params = $httpUtility->assembleParams($url, $config, array('xoauth_requestor_id' => $TWO_LEGGED_EMAIL_ADDRESS));
/**
* Sort parameters based on their names, as required
* by OAuth.
*/
ksort($params);
/**
* Construct a comma-deliminated,ordered,quoted list of
* OAuth params as required by XOAUTH.
*
* Example: oauth_param1="foo",oauth_param2="bar"
示例8: 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;
}
示例9: serialize
$consumer->redirect();
} else {
// Have Request Token already, Get Access Token
$_SESSION['ACCESS_TOKEN'] = serialize($consumer->getAccessToken($_GET, unserialize($_SESSION['REQUEST_TOKEN'])));
header('Location: ' . getCurrentUrl(false));
exit;
}
} else {
// Retrieve mail using Access Token
$accessToken = unserialize($_SESSION['ACCESS_TOKEN']);
$config = new Zend_Oauth_Config();
$config->setOptions($options);
$config->setToken($accessToken);
$config->setRequestMethod('GET');
$url = 'https://mail.google.com/mail/b/' . $email_address . '/imap/';
$httpUtility = new Zend_Oauth_Http_Utility();
/**
* Get an unsorted array of oauth params,
* including the signature based off those params.
*/
$params = $httpUtility->assembleParams($url, $config);
/**
* Sort parameters based on their names, as required
* by OAuth.
*/
ksort($params);
/**
* Construct a comma-deliminated,ordered,quoted list of
* OAuth params as required by XOAUTH.
*
* Example: oauth_param1="foo",oauth_param2="bar"
示例10: testBuildAuthorizationHeader
public function testBuildAuthorizationHeader()
{
$signature = 'valid_signature';
$this->_httpUtilityMock->expects($this->any())->method('sign')->will($this->returnValue($signature));
$this->_setupConsumer(false);
$this->_oauthHelperMock->expects($this->any())->method('generateRandomString')->will($this->returnValue('tyukmnjhgfdcvxstyuioplkmnhtfvert'));
$request = ['oauth_consumer_key' => 'edf957ef88492f0a32eb7e1731e85da2', 'oauth_consumer_secret' => 'asdawwewefrtyh2f0a32eb7e1731e85d', 'oauth_token' => '7c0709f789e1f38a17aa4b9a28e1b06c', 'oauth_token_secret' => 'a6agsfrsfgsrjjjjyy487939244ssggg', 'custom_param1' => 'foo', 'custom_param2' => 'bar'];
$requestUrl = 'http://www.example.com/endpoint';
$oauthHeader = $this->_oauth->buildAuthorizationHeader($request, $requestUrl);
$expectedHeader = 'OAuth oauth_nonce="tyukmnjhgfdcvxstyuioplkmnhtfvert",' . 'oauth_timestamp="",' . 'oauth_version="1.0",oauth_consumer_key="edf957ef88492f0a32eb7e1731e85da2",' . 'oauth_consumer_secret="asdawwewefrtyh2f0a32eb7e1731e85d",' . 'oauth_token="7c0709f789e1f38a17aa4b9a28e1b06c",' . 'oauth_token_secret="a6agsfrsfgsrjjjjyy487939244ssggg",' . 'oauth_signature="valid_signature"';
$this->assertEquals($expectedHeader, $oauthHeader, 'Generated Oauth header is incorrect');
}
示例11: toString
/**
* Convert Token to a string, specifically a raw encoded query string.
*
* @return string
*/
public function toString()
{
return $this->_httpUtility->toEncodedQueryString($this->_params);
}