Go to file
Adrian Palmer 33d3488ce2 Merge pull request #8 from rubensayshi/guzzle-v6
Guzzle6 (using PSR7)
2016-10-17 09:27:32 +11:00
examples Update package to support Guzzle 6 and stop supporting old versions. 2016-09-27 12:47:43 +02:00
src/HttpSignatures Update package to support Guzzle 6 and stop supporting old versions. 2016-09-27 12:47:43 +02:00
tests Update package to support Guzzle 6 and stop supporting old versions. 2016-09-27 12:47:43 +02:00
.gitignore Initial commit 2014-08-27 17:45:39 +10:00
.travis.yml Update package to support Guzzle 6 and stop supporting old versions. 2016-09-27 12:47:43 +02:00
LICENSE Initial commit 2014-10-06 20:06:36 +11:00
LICENSE.txt Initial commit 2014-08-27 17:45:39 +10:00
README.md Update package to support Guzzle 6 and stop supporting old versions. 2016-09-27 12:47:43 +02:00
composer.json Update package to support Guzzle 6 and stop supporting old versions. 2016-09-27 12:47:43 +02:00
phpunit.xml.dist Add phpunit.xml.dist 2014-08-27 17:47:56 +10:00

README.md

HTTP Signatures Guzzle 6

Guzzle 6 support for 99designs http-signatures library

Build Status

Adds 99designs/http-signatures support to Guzzle 6.

Older Guzzle Versions

For Guzzle 4 & 5 use the v1.x release of this repo. For Guzzle 3 see the 99designs/http-signatures-guzzle repo.

Signing with Guzzle 6

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.

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:

<?php

use GuzzleHttp\Client;
use GuzzleHttp\Handler\CurlHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
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 = new HandlerStack();
$stack->setHandler(new CurlHandler());
$stack->push(GuzzleHttpSignatures::middlewareFromContext($this->context));
$stack->push(Middleware::history($this->history));
$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']]);

Contributing

Pull Requests are welcome.