complex-media / guzzle-hawk
A GuzzlePHP plugin for Hawk authentication
v0.1.0
2015-10-14 19:07 UTC
Requires
- php: >=5.4.0
- dflydev/hawk: *
- guzzlehttp/guzzle: 4.1.*
This package is not auto-updated.
Last update: 2024-06-22 16:18:47 UTC
README
A Hawk Authenticator for Guzzle. ![](https://camo.githubusercontent.com/ee71bd6c2e15774336d14b56be665b13157967101a3953e7976a8602a863e4ed/68747470733a2f2f67612d626561636f6e2e61707073706f742e636f6d2f55412d36383839393438312d312f67757a7a6c652d6861776b2f726561646d653f706978656c)
Originally developed by jeskew, this extremely simple Plugin provides middleware you can place on your Guzzle client to automagically sign your requests.
Usage
First, install with Composer:
composer require complex-media/guzzle-hawk
Then, use it in code.
use ComplexMedia\Guzzle\Plugin\Hawk;
use GuzzleHttp\Client as Guzzle;
$client = new Guzzle();
$signer = new Hawk($key, $secret, $algorithm, $offset);
$client->getEmitter()->attach($signer);
$response = $client->get($URL);
$algorithm
will default to 'sha256'
, but you can set it to whatever your system supports.
$offset
adds a clock skew to synchronize with your server, and defaults to 0
. If you
get a 401 from your server, you can adjust several properties on the signer and try again
immediately:
$signer->key = $new_key
$signer->secret = $new_secret
$signer->algorithm = $new_algorithm
$signer->offset = $new_offset
$response = $client->get($URL);
Contributing
Yes
License
MIT License applies.