All Projects → spatie → Laravel Url Signer

spatie / Laravel Url Signer

Licence: mit
Create and validate signed URLs with a limited lifetime

Projects that are alternatives of or similar to Laravel Url Signer

Laravel Url Shortener
Powerful URL shortening tools in Laravel
Stars: ✭ 80 (-86.91%)
Mutual labels:  laravel, url
Laravel Short Url
A Laravel package to shorten urls
Stars: ✭ 127 (-79.21%)
Mutual labels:  laravel, url
Laravel Mail Preview
A mail driver to quickly preview mail
Stars: ✭ 851 (+39.28%)
Mutual labels:  laravel, mail
Laravel Mailbox
Catch incoming emails in your Laravel application
Stars: ✭ 783 (+28.15%)
Mutual labels:  laravel, mail
Url Signer
Create and validate signed URLs with a limited lifetime
Stars: ✭ 273 (-55.32%)
Mutual labels:  mail, url
Laravel Mailable Test
An artisan command to easily test mailables
Stars: ✭ 143 (-76.6%)
Mutual labels:  laravel, mail
Laravel Mail Editor
MailEclipse ⚡ Laravel Mailable Editor!
Stars: ✭ 1,714 (+180.52%)
Mutual labels:  laravel, mail
Laravel Welcome Notification
Send a welcome notification to new users
Stars: ✭ 299 (-51.06%)
Mutual labels:  laravel, mail
Urlhub
URL shortener web application based on the Laravel PHP Framework.
Stars: ✭ 217 (-64.48%)
Mutual labels:  laravel, url
Laravel Disposable Email
Disposable email address validator for Laravel
Stars: ✭ 147 (-75.94%)
Mutual labels:  laravel, mail
Mailgun
Mailgun package for Laravel
Stars: ✭ 297 (-51.39%)
Mutual labels:  laravel, mail
Laravel Mail Viewer
View all the mailables in your laravel app at a single place
Stars: ✭ 315 (-48.45%)
Mutual labels:  laravel, mail
Laravel Failed Job Monitor
Get notified when a queued job fails
Stars: ✭ 582 (-4.75%)
Mutual labels:  laravel
Laravel Server Monitor
Don't let your servers just melt down
Stars: ✭ 595 (-2.62%)
Mutual labels:  laravel
Laravel Visits
📊 Laravel Visits is a counter that can be attached to any model to track its visits using Redis or Eloquent. (with tags, IP protection and caching)
Stars: ✭ 582 (-4.75%)
Mutual labels:  laravel
Hydroxide
A third-party, open-source ProtonMail CardDAV, IMAP and SMTP bridge
Stars: ✭ 578 (-5.4%)
Mutual labels:  mail
Litstack
Build content-administration-panels in Laravel
Stars: ✭ 602 (-1.47%)
Mutual labels:  laravel
Laravel Initializer
A convenient way to initialize your application
Stars: ✭ 597 (-2.29%)
Mutual labels:  laravel
Lumen Generator
A Lumen Generator You Are Missing
Stars: ✭ 578 (-5.4%)
Mutual labels:  laravel
Laravel Mysql Spatial
MySQL Spatial Data Extension integration with Laravel.
Stars: ✭ 578 (-5.4%)
Mutual labels:  laravel

THIS PACKAGE IS NOT MAINTAINED ANYMORE. SIGNING URLS IS NOW PART OF LARAVEL: https://laravel-news.com/signed-routes

Create secured URLs with a limited lifetime in Laravel

Latest Version on Packagist Build Status Quality Score StyleCI Total Downloads

This package can create URLs with a limited lifetime. This is done by adding an expiration date and a signature to the URL.

This is how you can create signed URL that's valid for 30 days:

UrlSigner::sign('https://myapp.com/protected-route', 30);

The output will look like this:

https://app.com/protected-route?expires=xxxxxx&signature=xxxxxx

The URL can be validated with the validate-function.

UrlSigner::validate('https://app.com/protected-route?expires=xxxxxx&signature=xxxxxx');

The package also provides a middleware to protect routes.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

As you would have guessed the package can be installed via Composer:

composer require spatie/laravel-url-signer

In Laravel 5.5 the service provider and facade will automatically get registered. In older versions of the framework, just add the serviceprovider, and optionally register the facade:

// config/app.php

'providers' => [
    ...
    Spatie\UrlSigner\Laravel\UrlSignerServiceProvider::class,
];

'aliases' => [
    ...
    'UrlSigner' => Spatie\UrlSigner\Laravel\UrlSignerFacade::class,
];

Configuration

The configuration file can optionally be published via:

php artisan vendor:publish --provider="Spatie\UrlSigner\Laravel\UrlSignerServiceProvider"

This is the content of the file:

return [

    /*
    * This string is used the to generate a signature. You should
    * keep this value secret.
    */
    'signatureKey' => env('APP_KEY'),

    /*
     * The default expiration time of a URL in days.
     */
    'default_expiration_time_in_days' => 1,

    /*
     * These strings are used a parameter names in a signed url.
     */
    'parameters' => [
        'expires' => 'expires',
        'signature' => 'signature',
    ],

];

Usage

Signing URLs

URL's can be signed with the sign-method:

UrlSigner::sign('https://myapp.com/protected-route');

By default the lifetime of an URL is one day. This value can be change in the config-file. If you want a custom life time, you can specify the number of days the URL should be valid:

//the generated URL will be valid for 5 days.
UrlSigner::sign('https://myapp.com/protected-route', 5);

For fine grained control, you may also pass a DateTime instance as the second parameter. The url will be valid up to that moment. This example uses Carbon for convenience:

//This URL will be valid up until 2 hours from the moment it was generated.
UrlSigner::sign('https://myapp.com/protected-route', Carbon\Carbon::now()->addHours(2) );

Validating URLs

To validate a signed URL, simply call the validate()-method. This return a boolean.

UrlSigner::validate('https://app.com/protected-route?expires=xxxxxx&signature=xxxxxx');

Protecting routes with middleware

The package also provides a middleware to protect routes:

Route::get('protected-route', ['middleware' => 'signedurl', function () {
    return 'Hello secret world!';
}]);

Your app will abort with a 403 status code if the route is called without a valid signature.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ vendor/bin/phpunit

Usage outside Laravel

If you're working on a non-Laravel project, you can use the framework agnostic version.

Similar libraries

If you need signed url's for CloudFront, consider dreamonkey's package, which is based on this library.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].