This package can create URLs with or without a limited lifetime. This is done by adding an expiration date and a signature to the URL.
$urlSigner = new UrlSigner();
$urlSigner->setKeyResolver(function() {
return 'randomKey';
});
$signedUrl = $urlSigner->sign('https://myapp.com', [
'api_token' => 'aisj2jifeji3i'
]);
echo $signedUrl;
// => The generated url will be always valid
// => This will output an URL that looks like 'https://myapp.com/?api_token=aisj2jifeji3i&signature=xxxx'.
$signedUrl = $urlSigner->temporarySign('https://myapp.com', 30);
echo $signedUrl;
// => The generated url will be valid for 30 days
// => This will output an URL that looks like 'https://myapp.com/?expires=xxxx&signeture=xxxx'
The signature will be generated using the sha256
algorithm.
Imagine mailing this URL out to the users of your application. When a user clicks on a signed URL your application can validate it with:
$urlSigner->validate('https://myapp.com/?expires=xxxx&signature=xxxx');
The package can installed via Composer:
composer require anthonysan95/url-signer
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please make an issue in the issue tracker.
The MIT License (MIT). Please see License File for more information.