https://github.com/krakphp/hmac
Hmac Library
https://github.com/krakphp/hmac
Last synced: about 1 year ago
JSON representation
Hmac Library
- Host: GitHub
- URL: https://github.com/krakphp/hmac
- Owner: krakphp
- License: mit
- Created: 2016-04-25T22:40:58.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-04-25T22:42:43.000Z (about 10 years ago)
- Last Synced: 2025-01-29T06:52:18.624Z (over 1 year ago)
- Language: PHP
- Size: 20.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hmac
Hmac is a library for handling hmac authentication. Look at the source code for documentation.
## Usage
```php
'CustomHmac', // authentication scheme. Authorization: :
'hasher' => new Hmac\StdHmacHasher(), // any HmacHasher instance, defaults to Base64HmacHasher(StdHmacHasher)
'hs_gen' => hmac\hmac_hashed_hs_gen(), // any hash string generator function
'time_gen' => hmac\hmac_date_time_gen() // any time_gen function for generating a unit of time
'time_header' => 'Date',
'auth_header' => 'Authorization',
]);
$sign = hmac\hmac_sign_request($config);
$auth = hmac\hmac_auth_request($provider, $config);
```
### Signers
```
hmac_sign_request(HmacConfing = null);
hmac_psr7_sign_request(HmacConfing = null);
hmac_psr7_sign($sign);
```
`hmac_sign_request` is the default signer which creates sign function that accepts an `HmacRequest` and `HmacKeyPair`.
`hmac_psr7_sign_request` is a decorated signer around the hmac_sign_request for accepting and returning Psr Http Requests. It simply just wraps `hmac_sign_request` around the `hmac_psr7_sign` decorator.
`hmac_psr7_sign` is a decorator sign function that accepts a sign function and wraps it and returns a sign function that will accept and return Psr Http Requests.
### Hash String Generator
The hash string generators are functions that take the request and time value and generate the string that will end up being hashed.
provided `hs_gen` funcs:
// returns a hs_gen that will md5 hash the content and join everything by the given separator
hmac_hashed_hs_gen($sep = "\n");
example:
```php
getUri() . $time;
};
}
```
### Time Generator
A time generator is just used to generate a time unit like a timestamp or date stamp.
provided `time_gen` funcs:
// returns the `time` function which creates a unix timestamp
hmac_ts_time_gen();
// returns a time_gen which creates an RFC 2822 formatted date
hmac_date_time_gen();
## Integration
### GuzzleHttp
Simple integration with Guzzle can be done via the `Provider/guzzle.php` functions.
```php
push(guzzle_hmac_middleware(hmac_psr7_sign_request(), $keypair));
$client = new Client(['handler' => $handler]);
```