PHP code example of iamtartan / laravel-hmac-signature
1. Go to this page and download the library: Download iamtartan/laravel-hmac-signature library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
iamtartan / laravel-hmac-signature example snippets
use Tartan\Signature\Token;
use Tartan\Signature\Request;
$data = [
'first_name' => 'Aboozar',
'last_name' => 'Ghaffari',
'email' => '[email protected]'
];
$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;
}
// 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-');
$auth->attempt($token, 'x-');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.