public function onBefore(BeforeEvent $event) { $request = $event->getRequest(); $this->context->signer()->sign(new Message($request)); $headers = new MessageHeaders($request); $headers->set("Authorization", $headers->get("Signature")); $request->removeHeader("Signature"); }
/** * @param Context $context * @return \Closure */ public static function middlewareFromContext(Context $context) { return function (callable $handler) use($context) { return function (Request $request, array $options) use($handler, $context) { $request = $context->signer()->sign($request); return $handler($request, $options); }; }; }
public function testHMAC() { $context = new Context(array('keys' => array('pda' => 'secret'), 'algorithm' => 'hmac-sha256', 'headers' => array('(request-target)', 'date'))); $client = new \GuzzleHttp\Client(['auth' => 'http-signatures']); $client->getEmitter()->attach(new RequestSubscriber($context)); $message = $client->createRequest('GET', '/path?query=123', array('headers' => array('date' => 'today', 'accept' => 'llamas'))); $context->signer()->sign(new Message($message)); $expectedString = implode(',', array('keyId="pda"', 'algorithm="hmac-sha256"', 'headers="(request-target) date"', 'signature="SFlytCGpsqb/9qYaKCQklGDvwgmrwfIERFnwt+yqPJw="')); $this->assertEquals($expectedString, (string) $message->getHeader('Signature')); }
function signature_middleware_factory(Context $context) { return function (callable $handler) use($context) { return function (RequestInterface $request, array $options) use($handler, $context) { $message = new Message($request); $context->signer()->sign($message); $request = $request->withHeader("Authorization", $message->headers->get("Signature")); return $handler($request, $options); }; }; }
/** * @dataProvider getVerifyGuzzleRequestVectors * @param string $path * @param array $headers */ public function testVerifyGuzzleRequest($path, $headers) { $this->client->get($path, ['headers' => $headers]); // get last request $message = end($this->history); /** @var Request $request */ $request = $message['request']; /** @var Response $response */ $response = $message['request']; $this->assertTrue($this->context->verifier()->isValid($request)); }
public function testVerifyGuzzleRequest() { $message = $this->client->get('/path?query=123', array('date' => 'today', 'accept' => 'dogs')); $this->assertTrue($this->context->verifier()->isValid(new Message($message))); }
/** * @param Event $e */ public function signRequest($e) { $request = new Message($e['request']); $this->context->signer()->sign($request); }