Permalink
Browse files

Merge branch 'guss77-patch-1' into update-v1-to-guzzle-v6

# Conflicts:
#	composer.json
#	src/Client/Signature/HmacSha1Signature.php
  • Loading branch information...
2 parents 19de185 + 988308a commit fca5f160650cb74d23fc11aa570dd61f86dcf647 @bencorlett bencorlett committed Aug 17, 2016
Showing with 25 additions and 19 deletions.
  1. +1 −1 composer.json
  2. +24 −18 src/Client/Signature/HmacSha1Signature.php
View
@@ -3,7 +3,7 @@
"description": "OAuth 1.0 Client Library",
"license": "MIT",
"require": {
- "php": ">=5.3.0",
+ "php": ">=5.5.0",
"guzzlehttp/guzzle": "^6.0"
},
"require-dev": {
@@ -2,7 +2,8 @@
namespace League\OAuth1\Client\Signature;
-use Guzzle\Http\Url;
+use GuzzleHttp\Psr7;
+use GuzzleHttp\Psr7\Uri;
class HmacSha1Signature extends Signature implements SignatureInterface
{
@@ -19,12 +20,26 @@ public function method()
*/
public function sign($uri, array $parameters = array(), $method = 'POST')
{
- $baseString = $this->baseString($uri, $method, $parameters);
+ $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.
*
@@ -34,29 +49,20 @@ public function sign($uri, array $parameters = array(), $method = 'POST')
*
* @return string
*/
- protected function baseString($url, $method = 'POST', array $parameters = array())
+ protected function baseString(Uri $url, $method = 'POST', array $parameters = array())
{
$baseString = rawurlencode($method).'&';
- $parsedUrl = parse_url($url);
- if (!isset($parsedUrl['query'])) {
- $parsedUrl['query'] = '';
- }
-
- $schemeHostPath = sprintf(
- '%s://%s',
- $parsedUrl['scheme'],
- $parsedUrl['host']
- );
-
- if ($parsedUrl['path']) {
- $schemeHostPath .= '/'.ltrim($parsedUrl['path'], '/');
- }
+ $schemeHostPath = Uri::fromParts(array(
+ 'scheme' => $url->getScheme(),
+ 'host' => $url->getHost(),
+ 'path' => $url->getPath(),
+ ));
$baseString .= rawurlencode($schemeHostPath).'&';
$data = array();
- parse_str($parsedUrl['query'], $query);
+ parse_str($url->getQuery(), $query);
$data = array_merge($query, $parameters);
// normalize data key/values

0 comments on commit fca5f16

Please sign in to comment.