Package Data | |
---|---|
Maintainer Username: | tartan |
Maintainer Contact: | iamtartan@gmail.com (Aboozar Ghaffari <Tartan>) |
Package Create Date: | 2017-01-21 |
Package Last Update: | 2017-01-30 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:02:08 |
Package Statistics | |
---|---|
Total Downloads: | 814 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 8 |
Total Watchers: | 3 |
Total Forks: | 2 |
Total Open Issues: | 0 |
**A laravel HMAC auth package based on Signature-PHP **
Add iamtartan/laravel-hmac-signature
as a requirement to composer.json
:
$ composer require iamtartan/laravel-hmac-signature
HMAC-SHA authentication allows you to implement very simple key / secret authentication for your API using hashed signatures.
use Tartan\Signature\Token;
use Tartan\Signature\Request;
$data = [
'first_name' => 'Aboozar',
'last_name' => 'Ghaffari',
'email' => 'iamtartan@gmail.com'
];
$token = new Token('my_public_key', 'my_private_key');
$request = new Request('POST', 'signup', $data, '1.0.0');
$auth = $request->sign($token);
$finalData = array_merge($auth, $data);
$yourHttpClient->post('signup', $finalData);
use Tartan\Signature\Auth;
use Tartan\Signature\Token;
use Tartan\Signature\Guards\CheckKey;
use Tartan\Signature\Guards\CheckVersion;
use Tartan\Signature\Guards\CheckTimestamp;
use Tartan\Signature\Guards\CheckSignature;
use Tartan\Signature\Exceptions\SignatureException;
$auth = new Auth($request->method(), $request->url(), '1.0.0', $request->all(), [
new CheckKey,
new CheckVersion,
new CheckTimestamp,
new CheckSignature
]);
$token = new Token('my_public_key', 'my_private_key');
try {
$auth->attempt($token);
}
catch (SignatureException $e) {
// return 401
}
catch (Exception $e) {
// return 400;
}
By default, this package uses auth_*
in requests. You can change this behaviour when signing and and authenticating requests:
// default, the HTTP request uses auth_version, auth_key, auth_timestamp and auth_signature
$request->sign($token);
// the HTTP request now uses x-version, x-key, x-timestamp and x-signature
$request->sign($token, 'x-');
If you changed the default, you will need to authenticate the request accordingly:
$auth->attempt($token, 'x-');