Skip to content

Commit de8c03d

Browse files
authored
Update README in preparation of the 4.0.0 release (#44)
1 parent 0823b18 commit de8c03d

1 file changed

Lines changed: 27 additions & 13 deletions

File tree

README.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Use [Composer](http://getcomposer.org) and add it as a dependency to your projec
1616
```json
1717
{
1818
"require": {
19-
"acquia/http-hmac-php": "~3.3.0"
19+
"acquia/http-hmac-php": "^4.0"
2020
}
2121
}
2222
```
@@ -28,26 +28,32 @@ Please refer to [Composer's documentation](https://github.com/composer/composer/
2828
### Sign an API request sent via Guzzle
2929

3030
```php
31-
3231
use Acquia\Hmac\Guzzle\HmacAuthMiddleware;
3332
use Acquia\Hmac\Key;
3433
use GuzzleHttp\Client;
3534
use GuzzleHttp\HandlerStack;
3635

37-
// Optionally, you can provide signed headers to generate the digest. The header keys need to be provided to the middleware below.
38-
$options = [
39-
'headers' => [
36+
// Create the HTTP HMAC key.
37+
// A key consists of and ID and a Base64-encoded shared secret.
38+
// Note: the API provider may have already encoded the secret. In this case, it should not be re-encoded.
39+
$key_id = 'e7fe97fa-a0c8-4a42-ab8e-2c26d52df059';
40+
$key_secret = base64_encode('secret');
41+
$key = new Key($key_id, $key_secret);
42+
43+
// Optionally, you can provide additional headers when generating the signature.
44+
// The header keys need to be provided to the middleware below.
45+
$headers = [
4046
'X-Custom-1' => 'value1',
4147
'X-Custom-2' => 'value2',
42-
],
4348
];
4449

45-
// A key consists of your UUID and a Base64-encoded shared secret.
46-
// Note: the API provider may have already encoded the secret. In this case, it should not be re-encoded.
47-
$key = new Key('e7fe97fa-a0c8-4a42-ab8e-2c26d52df059', base64_encode('secret'));
50+
// Specify the API's realm.
51+
// Consult the API documentation for this value.
52+
$realm = 'Acquia';
4853

49-
// Provide your key, realm and optional signed headers.
50-
$middleware = new HmacAuthMiddleware($key, 'CIStore', array_keys($options['headers']));
54+
// Create a Guzzle middleware to handle authentication during all requests.
55+
// Provide your key, realm and the names of any additional custom headers.
56+
$middleware = new HmacAuthMiddleware($key, $realm, array_keys($headers)));
5157

5258
// Register the middleware.
5359
$stack = HandlerStack::create();
@@ -59,8 +65,16 @@ $client = new Client([
5965
]);
6066

6167
// Request.
62-
$result = $client->get('https://service.acquia.io/api/v1/widget', $options);
63-
var_dump($result);
68+
try {
69+
$result = $client->get('https://service.acquia.io/api/v1/widget', [
70+
'headers' => $headers,
71+
]);
72+
} catch (ClientException $e) {
73+
print $e->getMessage();
74+
$response = $e->getResponse();
75+
}
76+
77+
print $response->getBody();
6478
```
6579

6680
### Authenticate the request using PSR-7-compatible requests

0 commit comments

Comments
 (0)