mingalevme/utils-secure-link

1.0.2 2018-05-28 13:59 UTC

This package is auto-updated.

Last update: 2024-11-08 02:07:32 UTC


README

Simple HMAC implementation with TTL support for public urls

Travis CI

Build Status

Codecov

codecov

Installation

  1. composer require mingalevme/utils-secure-link.

  2. Now you are able to use the tool:

<?php

const SECRET = 'YOUR_SECRET_KEY';

use Mingalevme\Utils\Url\SecureLink;

$signer1 = new SecureLink(SECRET);

echo $signer1->sign('https://github.com/mingalevme/secure-link-php');
// https://github.com/mingalevme/secure-link-php?signature=13-dGaz-frzJ9qUg3iQ0RA%3D%3D

echo $signer1->sign('https://github.com/mingalevme/secure-link-php', 3600); 
// https://github.com/mingalevme/secure-link-php?expires=1526392953&signature=GOzCrktWlWDvSWVH49qjUQ%3D%3D

$signer2 = new SecureLink(SECRET, [
    'signatureArgName' => '_sig',
    'expiresArgName' => '_expires',
]);

echo $signer2->sign('https://github.com/mingalevme/secure-link-php', 3600);
// https://github.com/mingalevme/secure-link-php?_expires=1526393056&_sig=biyetWW5IgBPUftLF1SaOw%3D%3D

And validation

<?php

const SECRET = 'YOUR_SECRET_KEY';

use Mingalevme\Utils\Url\SecureLink;

$signer1 = new SecureLink(SECRET);

if (!$signer1->isValid('https://github.com/mingalevme/secure-link-php?_expires=1526393056&_sig=biyetWW5IgBPUftLF1SaOw%3D%3D')) {
    throw new Exception('Url is invalid or expired');
}