update 1.0.8.0
Commits for version update
This commit is contained in:
125
vendor/league/oauth1-client/src/Client/Signature/HmacSha1Signature.php
vendored
Normal file
125
vendor/league/oauth1-client/src/Client/Signature/HmacSha1Signature.php
vendored
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace League\OAuth1\Client\Signature;
|
||||
|
||||
use GuzzleHttp\Psr7;
|
||||
use GuzzleHttp\Psr7\Uri;
|
||||
|
||||
class HmacSha1Signature extends Signature implements SignatureInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function method()
|
||||
{
|
||||
return 'HMAC-SHA1';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function sign($uri, array $parameters = array(), $method = 'POST')
|
||||
{
|
||||
$url = $this->createUrl($uri);
|
||||
|
||||
$baseString = $this->baseString($url, $method, $parameters);
|
||||
|
||||
return base64_encode($this->hash($baseString));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a Guzzle url for the given URI.
|
||||
*
|
||||
* @param string $uri
|
||||
*
|
||||
* @return Url
|
||||
*/
|
||||
protected function createUrl($uri)
|
||||
{
|
||||
return Psr7\uri_for($uri);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a base string for a HMAC-SHA1 signature
|
||||
* based on the given a url, method, and any parameters.
|
||||
*
|
||||
* @param Url $url
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function baseString(Uri $url, $method = 'POST', array $parameters = array())
|
||||
{
|
||||
$baseString = rawurlencode($method).'&';
|
||||
|
||||
$schemeHostPath = Uri::fromParts(array(
|
||||
'scheme' => $url->getScheme(),
|
||||
'host' => $url->getHost(),
|
||||
'path' => $url->getPath(),
|
||||
));
|
||||
|
||||
$baseString .= rawurlencode($schemeHostPath).'&';
|
||||
|
||||
$data = array();
|
||||
parse_str($url->getQuery(), $query);
|
||||
$data = array_merge($query, $parameters);
|
||||
|
||||
// normalize data key/values
|
||||
array_walk_recursive($data, function (&$key, &$value) {
|
||||
$key = rawurlencode(rawurldecode($key));
|
||||
$value = rawurlencode(rawurldecode($value));
|
||||
});
|
||||
ksort($data);
|
||||
|
||||
$baseString .= $this->queryStringFromData($data);
|
||||
|
||||
return $baseString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an array of rawurlencoded strings out of each array key/value pair
|
||||
* Handles multi-demensional arrays recursively.
|
||||
*
|
||||
* @param array $data Array of parameters to convert.
|
||||
* @param array $queryParams Array to extend. False by default.
|
||||
* @param string $prevKey Optional Array key to append
|
||||
*
|
||||
* @return string rawurlencoded string version of data
|
||||
*/
|
||||
protected function queryStringFromData($data, $queryParams = false, $prevKey = '')
|
||||
{
|
||||
if ($initial = (false === $queryParams)) {
|
||||
$queryParams = array();
|
||||
}
|
||||
|
||||
foreach ($data as $key => $value) {
|
||||
if ($prevKey) {
|
||||
$key = $prevKey.'['.$key.']'; // Handle multi-dimensional array
|
||||
}
|
||||
if (is_array($value)) {
|
||||
$queryParams = $this->queryStringFromData($value, $queryParams, $key);
|
||||
} else {
|
||||
$queryParams[] = rawurlencode($key.'='.$value); // join with equals sign
|
||||
}
|
||||
}
|
||||
|
||||
if ($initial) {
|
||||
return implode('%26', $queryParams); // join with ampersand
|
||||
}
|
||||
|
||||
return $queryParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hashes a string with the signature's key.
|
||||
*
|
||||
* @param string $string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function hash($string)
|
||||
{
|
||||
return hash_hmac('sha1', $string, $this->key(), true);
|
||||
}
|
||||
}
|
||||
22
vendor/league/oauth1-client/src/Client/Signature/PlainTextSignature.php
vendored
Normal file
22
vendor/league/oauth1-client/src/Client/Signature/PlainTextSignature.php
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace League\OAuth1\Client\Signature;
|
||||
|
||||
class PlainTextSignature extends Signature implements SignatureInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function method()
|
||||
{
|
||||
return 'PLAINTEXT';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function sign($uri, array $parameters = array(), $method = 'POST')
|
||||
{
|
||||
return $this->key();
|
||||
}
|
||||
}
|
||||
55
vendor/league/oauth1-client/src/Client/Signature/Signature.php
vendored
Normal file
55
vendor/league/oauth1-client/src/Client/Signature/Signature.php
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace League\OAuth1\Client\Signature;
|
||||
|
||||
use League\OAuth1\Client\Credentials\ClientCredentialsInterface;
|
||||
use League\OAuth1\Client\Credentials\CredentialsInterface;
|
||||
|
||||
abstract class Signature implements SignatureInterface
|
||||
{
|
||||
/**
|
||||
* The client credentials.
|
||||
*
|
||||
* @var ClientCredentialsInterface
|
||||
*/
|
||||
protected $clientCredentials;
|
||||
|
||||
/**
|
||||
* The (temporary or token) credentials.
|
||||
*
|
||||
* @var CredentialsInterface
|
||||
*/
|
||||
protected $credentials;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function __construct(ClientCredentialsInterface $clientCredentials)
|
||||
{
|
||||
$this->clientCredentials = $clientCredentials;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setCredentials(CredentialsInterface $credentials)
|
||||
{
|
||||
$this->credentials = $credentials;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a signing key.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function key()
|
||||
{
|
||||
$key = rawurlencode($this->clientCredentials->getSecret()).'&';
|
||||
|
||||
if ($this->credentials !== null) {
|
||||
$key .= rawurlencode($this->credentials->getSecret());
|
||||
}
|
||||
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
44
vendor/league/oauth1-client/src/Client/Signature/SignatureInterface.php
vendored
Normal file
44
vendor/league/oauth1-client/src/Client/Signature/SignatureInterface.php
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace League\OAuth1\Client\Signature;
|
||||
|
||||
use League\OAuth1\Client\Credentials\ClientCredentialsInterface;
|
||||
use League\OAuth1\Client\Credentials\CredentialsInterface;
|
||||
|
||||
interface SignatureInterface
|
||||
{
|
||||
/**
|
||||
* Create a new signature instance.
|
||||
*
|
||||
* @param ClientCredentialsInterface $clientCredentials
|
||||
*/
|
||||
public function __construct(ClientCredentialsInterface $clientCredentials);
|
||||
|
||||
/**
|
||||
* Set the credentials used in the signature. These can be temporary
|
||||
* credentials when getting token credentials during the OAuth
|
||||
* authentication process, or token credentials when querying
|
||||
* the API.
|
||||
*
|
||||
* @param CredentialsInterface $credentials
|
||||
*/
|
||||
public function setCredentials(CredentialsInterface $credentials);
|
||||
|
||||
/**
|
||||
* Get the OAuth signature method.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function method();
|
||||
|
||||
/**
|
||||
* Sign the given request for the client.
|
||||
*
|
||||
* @param string $uri
|
||||
* @param array $parameters
|
||||
* @param string $method
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function sign($uri, array $parameters = array(), $method = 'POST');
|
||||
}
|
||||
Reference in New Issue
Block a user