init
This commit is contained in:
189
Zend/Oauth/Http/AccessToken.php
Normal file
189
Zend/Oauth/Http/AccessToken.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Oauth
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/** Zend_Oauth_Http */
|
||||
require_once 'Zend/Oauth/Http.php';
|
||||
|
||||
/** Zend_Oauth_Token_Access */
|
||||
require_once 'Zend/Oauth/Token/Access.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Oauth
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Oauth_Http_AccessToken extends Zend_Oauth_Http
|
||||
{
|
||||
/**
|
||||
* Singleton instance if required of the HTTP client
|
||||
*
|
||||
* @var Zend_Http_Client
|
||||
*/
|
||||
protected $_httpClient = null;
|
||||
|
||||
/**
|
||||
* Initiate a HTTP request to retrieve an Access Token.
|
||||
*
|
||||
* @return Zend_Oauth_Token_Access
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$params = $this->assembleParams();
|
||||
$response = $this->startRequestCycle($params);
|
||||
$return = new Zend_Oauth_Token_Access($response);
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assemble all parameters for an OAuth Access Token request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function assembleParams()
|
||||
{
|
||||
$params = array(
|
||||
'oauth_consumer_key' => $this->_consumer->getConsumerKey(),
|
||||
'oauth_nonce' => $this->_httpUtility->generateNonce(),
|
||||
'oauth_signature_method' => $this->_consumer->getSignatureMethod(),
|
||||
'oauth_timestamp' => $this->_httpUtility->generateTimestamp(),
|
||||
'oauth_token' => $this->_consumer->getLastRequestToken()->getToken(),
|
||||
'oauth_version' => $this->_consumer->getVersion(),
|
||||
);
|
||||
|
||||
if (!empty($this->_parameters)) {
|
||||
$params = array_merge($params, $this->_parameters);
|
||||
}
|
||||
|
||||
$params['oauth_signature'] = $this->_httpUtility->sign(
|
||||
$params,
|
||||
$this->_consumer->getSignatureMethod(),
|
||||
$this->_consumer->getConsumerSecret(),
|
||||
$this->_consumer->getLastRequestToken()->getTokenSecret(),
|
||||
$this->_preferredRequestMethod,
|
||||
$this->_consumer->getAccessTokenUrl()
|
||||
);
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate and return a HTTP Client configured for the Header Request Scheme
|
||||
* specified by OAuth, for use in requesting an Access Token.
|
||||
*
|
||||
* @param array $params
|
||||
* @return Zend_Http_Client
|
||||
*/
|
||||
public function getRequestSchemeHeaderClient(array $params)
|
||||
{
|
||||
$params = $this->_cleanParamsOfIllegalCustomParameters($params);
|
||||
$headerValue = $this->_toAuthorizationHeader($params);
|
||||
$client = Zend_Oauth::getHttpClient();
|
||||
|
||||
$client->setUri($this->_consumer->getAccessTokenUrl());
|
||||
$client->setHeaders('Authorization', $headerValue);
|
||||
$client->setMethod($this->_preferredRequestMethod);
|
||||
|
||||
return $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate and return a HTTP Client configured for the POST Body Request
|
||||
* Scheme specified by OAuth, for use in requesting an Access Token.
|
||||
*
|
||||
* @param array $params
|
||||
* @return Zend_Http_Client
|
||||
*/
|
||||
public function getRequestSchemePostBodyClient(array $params)
|
||||
{
|
||||
$params = $this->_cleanParamsOfIllegalCustomParameters($params);
|
||||
$client = Zend_Oauth::getHttpClient();
|
||||
$client->setUri($this->_consumer->getAccessTokenUrl());
|
||||
$client->setMethod($this->_preferredRequestMethod);
|
||||
$client->setRawData(
|
||||
$this->_httpUtility->toEncodedQueryString($params)
|
||||
);
|
||||
$client->setHeaders(
|
||||
Zend_Http_Client::CONTENT_TYPE,
|
||||
Zend_Http_Client::ENC_URLENCODED
|
||||
);
|
||||
return $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate and return a HTTP Client configured for the Query String Request
|
||||
* Scheme specified by OAuth, for use in requesting an Access Token.
|
||||
*
|
||||
* @param array $params
|
||||
* @param string $url
|
||||
* @return Zend_Http_Client
|
||||
*/
|
||||
public function getRequestSchemeQueryStringClient(array $params, $url)
|
||||
{
|
||||
$params = $this->_cleanParamsOfIllegalCustomParameters($params);
|
||||
return parent::getRequestSchemeQueryStringClient($params, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt a request based on the current configured OAuth Request Scheme and
|
||||
* return the resulting HTTP Response.
|
||||
*
|
||||
* @param array $params
|
||||
* @return Zend_Http_Response
|
||||
*/
|
||||
protected function _attemptRequest(array $params)
|
||||
{
|
||||
switch ($this->_preferredRequestScheme) {
|
||||
case Zend_Oauth::REQUEST_SCHEME_HEADER:
|
||||
$httpClient = $this->getRequestSchemeHeaderClient($params);
|
||||
break;
|
||||
case Zend_Oauth::REQUEST_SCHEME_POSTBODY:
|
||||
$httpClient = $this->getRequestSchemePostBodyClient($params);
|
||||
break;
|
||||
case Zend_Oauth::REQUEST_SCHEME_QUERYSTRING:
|
||||
$httpClient = $this->getRequestSchemeQueryStringClient($params,
|
||||
$this->_consumer->getAccessTokenUrl());
|
||||
break;
|
||||
}
|
||||
return $httpClient->request();
|
||||
}
|
||||
|
||||
/**
|
||||
* Access Token requests specifically may not contain non-OAuth parameters.
|
||||
* So these should be striped out and excluded. Detection is easy since
|
||||
* specified OAuth parameters start with "oauth_", Extension params start
|
||||
* with "xouth_", and no other parameters should use these prefixes.
|
||||
*
|
||||
* xouth params are not currently allowable.
|
||||
*
|
||||
* @param array $params
|
||||
* @return array
|
||||
*/
|
||||
protected function _cleanParamsOfIllegalCustomParameters(array $params)
|
||||
{
|
||||
foreach ($params as $key=>$value) {
|
||||
if (!preg_match("/^oauth_/", $key)) {
|
||||
unset($params[$key]);
|
||||
}
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
162
Zend/Oauth/Http/RequestToken.php
Normal file
162
Zend/Oauth/Http/RequestToken.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Oauth
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/** Zend_Oauth_Http */
|
||||
require_once 'Zend/Oauth/Http.php';
|
||||
|
||||
/** Zend_Oauth_Token_Request */
|
||||
require_once 'Zend/Oauth/Token/Request.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Oauth
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Oauth_Http_RequestToken extends Zend_Oauth_Http
|
||||
{
|
||||
/**
|
||||
* Singleton instance if required of the HTTP client
|
||||
*
|
||||
* @var Zend_Http_Client
|
||||
*/
|
||||
protected $_httpClient = null;
|
||||
|
||||
/**
|
||||
* Initiate a HTTP request to retrieve a Request Token.
|
||||
*
|
||||
* @return Zend_Oauth_Token_Request
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$params = $this->assembleParams();
|
||||
$response = $this->startRequestCycle($params);
|
||||
$return = new Zend_Oauth_Token_Request($response);
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assemble all parameters for an OAuth Request Token request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function assembleParams()
|
||||
{
|
||||
$params = array(
|
||||
'oauth_consumer_key' => $this->_consumer->getConsumerKey(),
|
||||
'oauth_nonce' => $this->_httpUtility->generateNonce(),
|
||||
'oauth_timestamp' => $this->_httpUtility->generateTimestamp(),
|
||||
'oauth_signature_method' => $this->_consumer->getSignatureMethod(),
|
||||
'oauth_version' => $this->_consumer->getVersion(),
|
||||
);
|
||||
|
||||
// indicates we support 1.0a
|
||||
if ($this->_consumer->getCallbackUrl()) {
|
||||
$params['oauth_callback'] = $this->_consumer->getCallbackUrl();
|
||||
} else {
|
||||
$params['oauth_callback'] = 'oob';
|
||||
}
|
||||
|
||||
if (!empty($this->_parameters)) {
|
||||
$params = array_merge($params, $this->_parameters);
|
||||
}
|
||||
|
||||
$params['oauth_signature'] = $this->_httpUtility->sign(
|
||||
$params,
|
||||
$this->_consumer->getSignatureMethod(),
|
||||
$this->_consumer->getConsumerSecret(),
|
||||
null,
|
||||
$this->_preferredRequestMethod,
|
||||
$this->_consumer->getRequestTokenUrl()
|
||||
);
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate and return a HTTP Client configured for the Header Request Scheme
|
||||
* specified by OAuth, for use in requesting a Request Token.
|
||||
*
|
||||
* @param array $params
|
||||
* @return Zend_Http_Client
|
||||
*/
|
||||
public function getRequestSchemeHeaderClient(array $params)
|
||||
{
|
||||
$headerValue = $this->_httpUtility->toAuthorizationHeader(
|
||||
$params
|
||||
);
|
||||
$client = Zend_Oauth::getHttpClient();
|
||||
$client->setUri($this->_consumer->getRequestTokenUrl());
|
||||
$client->setHeaders('Authorization', $headerValue);
|
||||
$rawdata = $this->_httpUtility->toEncodedQueryString($params, true);
|
||||
if (!empty($rawdata)) {
|
||||
$client->setRawData($rawdata);
|
||||
}
|
||||
$client->setMethod($this->_preferredRequestMethod);
|
||||
return $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate and return a HTTP Client configured for the POST Body Request
|
||||
* Scheme specified by OAuth, for use in requesting a Request Token.
|
||||
*
|
||||
* @param array $params
|
||||
* @return Zend_Http_Client
|
||||
*/
|
||||
public function getRequestSchemePostBodyClient(array $params)
|
||||
{
|
||||
$client = Zend_Oauth::getHttpClient();
|
||||
$client->setUri($this->_consumer->getRequestTokenUrl());
|
||||
$client->setMethod($this->_preferredRequestMethod);
|
||||
$client->setRawData(
|
||||
$this->_httpUtility->toEncodedQueryString($params)
|
||||
);
|
||||
$client->setHeaders(
|
||||
Zend_Http_Client::CONTENT_TYPE,
|
||||
Zend_Http_Client::ENC_URLENCODED
|
||||
);
|
||||
return $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt a request based on the current configured OAuth Request Scheme and
|
||||
* return the resulting HTTP Response.
|
||||
*
|
||||
* @param array $params
|
||||
* @return Zend_Http_Response
|
||||
*/
|
||||
protected function _attemptRequest(array $params)
|
||||
{
|
||||
switch ($this->_preferredRequestScheme) {
|
||||
case Zend_Oauth::REQUEST_SCHEME_HEADER:
|
||||
$httpClient = $this->getRequestSchemeHeaderClient($params);
|
||||
break;
|
||||
case Zend_Oauth::REQUEST_SCHEME_POSTBODY:
|
||||
$httpClient = $this->getRequestSchemePostBodyClient($params);
|
||||
break;
|
||||
case Zend_Oauth::REQUEST_SCHEME_QUERYSTRING:
|
||||
$httpClient = $this->getRequestSchemeQueryStringClient($params,
|
||||
$this->_consumer->getRequestTokenUrl());
|
||||
break;
|
||||
}
|
||||
return $httpClient->request();
|
||||
}
|
||||
}
|
||||
78
Zend/Oauth/Http/UserAuthorization.php
Normal file
78
Zend/Oauth/Http/UserAuthorization.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Oauth
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/** Zend_Oauth_Http */
|
||||
require_once 'Zend/Oauth/Http.php';
|
||||
|
||||
/** Zend_Uri_Http */
|
||||
require_once 'Zend/Uri/Http.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Oauth
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Oauth_Http_UserAuthorization extends Zend_Oauth_Http
|
||||
{
|
||||
/**
|
||||
* Generate a redirect URL from the allowable parameters and configured
|
||||
* values.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getUrl()
|
||||
{
|
||||
$params = $this->assembleParams();
|
||||
$uri = Zend_Uri_Http::fromString($this->_consumer->getUserAuthorizationUrl());
|
||||
|
||||
$uri->setQuery(
|
||||
$this->_httpUtility->toEncodedQueryString($params)
|
||||
);
|
||||
|
||||
return $uri->getUri();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assemble all parameters for inclusion in a redirect URL.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function assembleParams()
|
||||
{
|
||||
$params = array(
|
||||
'oauth_token' => $this->_consumer->getLastRequestToken()->getToken(),
|
||||
);
|
||||
|
||||
if (!Zend_Oauth_Client::$supportsRevisionA) {
|
||||
$callback = $this->_consumer->getCallbackUrl();
|
||||
if (!empty($callback)) {
|
||||
$params['oauth_callback'] = $callback;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->_parameters)) {
|
||||
$params = array_merge($params, $this->_parameters);
|
||||
}
|
||||
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
217
Zend/Oauth/Http/Utility.php
Normal file
217
Zend/Oauth/Http/Utility.php
Normal file
@@ -0,0 +1,217 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Oauth
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
*/
|
||||
|
||||
/** Zend_Oauth */
|
||||
require_once 'Zend/Oauth.php';
|
||||
|
||||
/** Zend_Oauth_Http */
|
||||
require_once 'Zend/Oauth/Http.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Oauth
|
||||
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Oauth_Http_Utility
|
||||
{
|
||||
/**
|
||||
* Assemble all parameters for a generic OAuth request - i.e. no special
|
||||
* params other than the defaults expected for any OAuth query.
|
||||
*
|
||||
* @param string $url
|
||||
* @param Zend_Oauth_Config_ConfigInterface $config
|
||||
* @param null|array $serviceProviderParams
|
||||
* @return array
|
||||
*/
|
||||
public function assembleParams(
|
||||
$url,
|
||||
Zend_Oauth_Config_ConfigInterface $config,
|
||||
array $serviceProviderParams = null
|
||||
) {
|
||||
$params = array(
|
||||
'oauth_consumer_key' => $config->getConsumerKey(),
|
||||
'oauth_nonce' => $this->generateNonce(),
|
||||
'oauth_signature_method' => $config->getSignatureMethod(),
|
||||
'oauth_timestamp' => $this->generateTimestamp(),
|
||||
'oauth_version' => $config->getVersion(),
|
||||
);
|
||||
|
||||
if ($config->getToken()->getToken() != null) {
|
||||
$params['oauth_token'] = $config->getToken()->getToken();
|
||||
}
|
||||
|
||||
|
||||
if ($serviceProviderParams !== null) {
|
||||
$params = array_merge($params, $serviceProviderParams);
|
||||
}
|
||||
|
||||
$params['oauth_signature'] = $this->sign(
|
||||
$params,
|
||||
$config->getSignatureMethod(),
|
||||
$config->getConsumerSecret(),
|
||||
$config->getToken()->getTokenSecret(),
|
||||
$config->getRequestMethod(),
|
||||
$url
|
||||
);
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given both OAuth parameters and any custom parametere, generate an
|
||||
* encoded query string. This method expects parameters to have been
|
||||
* assembled and signed beforehand.
|
||||
*
|
||||
* @param array $params
|
||||
* @param bool $customParamsOnly Ignores OAuth params e.g. for requests using OAuth Header
|
||||
* @return string
|
||||
*/
|
||||
public function toEncodedQueryString(array $params, $customParamsOnly = false)
|
||||
{
|
||||
if ($customParamsOnly) {
|
||||
foreach ($params as $key=>$value) {
|
||||
if (preg_match("/^oauth_/", $key)) {
|
||||
unset($params[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
$encodedParams = array();
|
||||
foreach ($params as $key => $value) {
|
||||
$encodedParams[] = self::urlEncode($key)
|
||||
. '='
|
||||
. self::urlEncode($value);
|
||||
}
|
||||
return implode('&', $encodedParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast to authorization header
|
||||
*
|
||||
* @param array $params
|
||||
* @param null|string $realm
|
||||
* @param bool $excludeCustomParams
|
||||
* @return void
|
||||
*/
|
||||
public function toAuthorizationHeader(array $params, $realm = null, $excludeCustomParams = true)
|
||||
{
|
||||
$headerValue = array(
|
||||
'OAuth realm="' . $realm . '"',
|
||||
);
|
||||
|
||||
foreach ($params as $key => $value) {
|
||||
if ($excludeCustomParams) {
|
||||
if (!preg_match("/^oauth_/", $key)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$headerValue[] = self::urlEncode($key)
|
||||
. '="'
|
||||
. self::urlEncode($value) . '"';
|
||||
}
|
||||
return implode(",", $headerValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign request
|
||||
*
|
||||
* @param array $params
|
||||
* @param string $signatureMethod
|
||||
* @param string $consumerSecret
|
||||
* @param null|string $tokenSecret
|
||||
* @param null|string $method
|
||||
* @param null|string $url
|
||||
* @return string
|
||||
*/
|
||||
public function sign(
|
||||
array $params, $signatureMethod, $consumerSecret, $tokenSecret = null, $method = null, $url = null
|
||||
) {
|
||||
$className = '';
|
||||
$hashAlgo = null;
|
||||
$parts = explode('-', $signatureMethod);
|
||||
if (count($parts) > 1) {
|
||||
$className = 'Zend_Oauth_Signature_' . ucfirst(strtolower($parts[0]));
|
||||
$hashAlgo = $parts[1];
|
||||
} else {
|
||||
$className = 'Zend_Oauth_Signature_' . ucfirst(strtolower($signatureMethod));
|
||||
}
|
||||
|
||||
require_once str_replace('_', '/', $className) . '.php';
|
||||
$signatureObject = new $className($consumerSecret, $tokenSecret, $hashAlgo);
|
||||
return $signatureObject->sign($params, $method, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse query string
|
||||
*
|
||||
* @param mixed $query
|
||||
* @return array
|
||||
*/
|
||||
public function parseQueryString($query)
|
||||
{
|
||||
$params = array();
|
||||
if (empty($query)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// Not remotely perfect but beats parse_str() which converts
|
||||
// periods and uses urldecode, not rawurldecode.
|
||||
$parts = explode('&', $query);
|
||||
foreach ($parts as $pair) {
|
||||
$kv = explode('=', $pair);
|
||||
$params[rawurldecode($kv[0])] = rawurldecode($kv[1]);
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate nonce
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generateNonce()
|
||||
{
|
||||
return md5(uniqid(rand(), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate timestamp
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function generateTimestamp()
|
||||
{
|
||||
return time();
|
||||
}
|
||||
|
||||
/**
|
||||
* urlencode a value
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public static function urlEncode($value)
|
||||
{
|
||||
$encoded = rawurlencode($value);
|
||||
$encoded = str_replace('%7E', '~', $encoded);
|
||||
return $encoded;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user