2015-11-09 17:11:11 +00:00
|
|
|
HTTP Signatures Guzzle 6
|
2014-10-06 09:07:16 +00:00
|
|
|
========================
|
2014-10-06 09:06:36 +00:00
|
|
|
|
2015-11-09 17:11:11 +00:00
|
|
|
Guzzle 6 support for 99designs http-signatures library
|
2014-08-27 07:45:39 +00:00
|
|
|
|
2014-10-06 08:21:26 +00:00
|
|
|
[![Build Status](https://travis-ci.org/99designs/http-signatures-guzzlehttp.svg)](https://travis-ci.org/99designs/http-signatures-guzzlehttp)
|
2014-08-27 23:59:31 +00:00
|
|
|
|
2015-11-09 17:11:11 +00:00
|
|
|
Adds [99designs/http-signatures][99signatures] support to Guzzle 6.
|
|
|
|
|
|
|
|
|
|
|
|
Older Guzzle Versions
|
|
|
|
---------------------
|
|
|
|
For Guzzle 4 & 5 use the `v1.x` release of this repo.
|
2014-10-27 23:15:56 +00:00
|
|
|
For Guzzle 3 see the [99designs/http-signatures-guzzle][99signatures-guzzle] repo.
|
2014-08-27 07:45:39 +00:00
|
|
|
|
2015-11-09 17:11:11 +00:00
|
|
|
|
|
|
|
Signing with Guzzle 6
|
2014-10-06 12:38:02 +00:00
|
|
|
---------------------
|
2014-08-27 07:45:39 +00:00
|
|
|
|
2015-11-09 17:11:11 +00:00
|
|
|
This library includes support for automatically signing Guzzle requests using Middleware.
|
|
|
|
|
|
|
|
You can use `GuzzleHttpSignatures::defaultHandlerFromContext` to easily create the default Guzzle handler with the
|
|
|
|
middleware added to sign every request.
|
|
|
|
|
|
|
|
```php
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
use HttpSignatures\Context;
|
|
|
|
use HttpSignatures\GuzzleHttpSignatures;
|
|
|
|
|
|
|
|
require __DIR__ . "/../vendor/autoload.php";
|
|
|
|
|
|
|
|
$context = new Context([
|
|
|
|
'keys' => ['examplekey' => 'secret-key-here'],
|
|
|
|
'algorithm' => 'hmac-sha256',
|
|
|
|
'headers' => ['(request-target)', 'date'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$handlerStack = GuzzleHttpSignatures::defaultHandlerFromContext($context);
|
|
|
|
$client = new Client(['handler' => $handlerStack]);
|
|
|
|
|
|
|
|
// The below will now send a signed request to: http://example.org/path?query=123
|
|
|
|
$response = $client->get("http://www.example.com/path?query=123", ['headers' => ['date' => 'today']]);
|
|
|
|
```
|
|
|
|
|
|
|
|
Or if you're creating a custom `HandlerStack` you can add the Middleware yourself:
|
2014-08-27 07:45:39 +00:00
|
|
|
|
|
|
|
```php
|
2015-11-09 17:11:11 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use GuzzleHttp\Client;
|
|
|
|
use GuzzleHttp\Handler\CurlHandler;
|
|
|
|
use GuzzleHttp\HandlerStack;
|
|
|
|
use GuzzleHttp\Middleware;
|
2014-08-27 23:59:31 +00:00
|
|
|
use HttpSignatures\Context;
|
2015-11-09 17:11:11 +00:00
|
|
|
use HttpSignatures\GuzzleHttpSignatures;
|
2014-08-27 07:45:39 +00:00
|
|
|
|
2015-11-09 17:11:11 +00:00
|
|
|
require __DIR__ . "/../vendor/autoload.php";
|
2014-08-27 23:59:31 +00:00
|
|
|
|
2015-11-09 17:11:11 +00:00
|
|
|
$context = new Context([
|
|
|
|
'keys' => ['examplekey' => 'secret-key-here'],
|
|
|
|
'algorithm' => 'hmac-sha256',
|
|
|
|
'headers' => ['(request-target)', 'date'],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$handlerStack = new HandlerStack();
|
|
|
|
$stack->setHandler(new CurlHandler());
|
|
|
|
$stack->push(GuzzleHttpSignatures::middlewareFromContext($this->context));
|
|
|
|
$stack->push(Middleware::history($this->history));
|
|
|
|
$client = new Client(['handler' => $handlerStack]);
|
2014-08-27 07:45:39 +00:00
|
|
|
|
|
|
|
// The below will now send a signed request to: http://example.org/path?query=123
|
2015-11-09 17:11:11 +00:00
|
|
|
$response = $client->get("http://www.example.com/path?query=123", ['headers' => ['date' => 'today']]);
|
2014-08-27 07:45:39 +00:00
|
|
|
```
|
|
|
|
|
2015-11-09 17:11:11 +00:00
|
|
|
|
2014-08-27 07:45:39 +00:00
|
|
|
## Contributing
|
|
|
|
|
|
|
|
Pull Requests are welcome.
|
2014-10-27 23:15:56 +00:00
|
|
|
|
|
|
|
[99signatures]: https://github.com/99designs/http-signatures-php
|
|
|
|
[99signatures-guzzle]: https://github.com/99designs/http-signatures-guzzle
|