From 0568cb14aa3ff87a07ab8edf38e1b8e1f98f9ee2 Mon Sep 17 00:00:00 2001 From: Jonathan Eskew Date: Fri, 27 Jun 2014 13:19:24 -0400 Subject: [PATCH 1/2] Parse the payload --- src/Jeskew/Guzzle/Plugin/Hawk.php | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Jeskew/Guzzle/Plugin/Hawk.php b/src/Jeskew/Guzzle/Plugin/Hawk.php index ce046fe..a0a0b7a 100644 --- a/src/Jeskew/Guzzle/Plugin/Hawk.php +++ b/src/Jeskew/Guzzle/Plugin/Hawk.php @@ -8,18 +8,28 @@ use GuzzleHttp\Event\BeforeEvent; use GuzzleHttp\Event\EmitterInterface; use GuzzleHttp\Event\SubscriberInterface; +use GuzzleHttp\Message\Request; class Hawk implements SubscriberInterface { private $key; private $secret; private $offset; + private $parsePayload; + private $extHeaders; - public function __construct($key, $secret, $offset = 0) - { + public function __construct( + $key, + $secret, + $offset = 0, + $parsePayload = false, + $extHeaders = [] + ) { $this->key = $key; $this->secret = $secret; $this->offset = $offset; + $this->parsePayload = $parsePayload; + $this->extHeaders = $extHeaders; } public function getEvents() @@ -38,7 +48,10 @@ public function signRequest(BeforeEvent $event) $this->secret, $request->getUrl(), $request->getMethod(), - $this->offset + $this->offset, + [], + $this->parsePayload ? (string) $request->getBody() : '', + $this->parsePayload ? $request->getHeader('content-type') : '' ); $request->setHeader( @@ -73,6 +86,11 @@ public function generateHawkRequest( return $request; } + private function gatherExtHeaders(Request $request) + { + $headers = $request->getHeaders(); + } + private function buildClient($offset) { $builder = ClientBuilder::create(); From d730132dd04cc2a8c64ca02920b8f850e5ad1cd9 Mon Sep 17 00:00:00 2001 From: Jonathan Eskew Date: Fri, 27 Jun 2014 13:23:48 -0400 Subject: [PATCH 2/2] Include ext headers --- src/Jeskew/Guzzle/Plugin/Hawk.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Jeskew/Guzzle/Plugin/Hawk.php b/src/Jeskew/Guzzle/Plugin/Hawk.php index a0a0b7a..a750cfe 100644 --- a/src/Jeskew/Guzzle/Plugin/Hawk.php +++ b/src/Jeskew/Guzzle/Plugin/Hawk.php @@ -8,7 +8,7 @@ use GuzzleHttp\Event\BeforeEvent; use GuzzleHttp\Event\EmitterInterface; use GuzzleHttp\Event\SubscriberInterface; -use GuzzleHttp\Message\Request; +use GuzzleHttp\Message\RequestInterface; class Hawk implements SubscriberInterface { @@ -49,7 +49,7 @@ public function signRequest(BeforeEvent $event) $request->getUrl(), $request->getMethod(), $this->offset, - [], + $this->gatherExtHeaders($request), $this->parsePayload ? (string) $request->getBody() : '', $this->parsePayload ? $request->getHeader('content-type') : '' ); @@ -86,9 +86,16 @@ public function generateHawkRequest( return $request; } - private function gatherExtHeaders(Request $request) + private function gatherExtHeaders(RequestInterface $request) { - $headers = $request->getHeaders(); + $headers = array_intersect_key( + $request->getHeaders(), + array_flip($this->extHeaders) + ); + + ksort($headers); + + return $headers; } private function buildClient($offset)