PHPackages                             spatie/laravel-url-signer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. spatie/laravel-url-signer

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

spatie/laravel-url-signer
=========================

Laravel implementation of spatie/signed-url

3.3.0(2mo ago)717784.1k—4.7%533MITPHPPHP ^8.1CI passing

Since Aug 15Pushed 2mo ago13 watchersCompare

[ Source](https://github.com/spatie/laravel-url-signer)[ Packagist](https://packagist.org/packages/spatie/laravel-url-signer)[ Docs](https://github.com/spatie/laravel-url-signer)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/spatie-laravel-url-signer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (24)Used By (3)

Create signed URLs with a limited lifetime in Laravel
=====================================================

[](#create-signed-urls-with-a-limited-lifetime-in-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0dd96cc4b073bcc2359d364372d1d3f36999f16ce5e5e94abd1cd3ed6057609e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d75726c2d7369676e65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-url-signer)[![Build Status](https://camo.githubusercontent.com/8bffe7b4fb65a5d8762efad9341fb4768d0b3a30494f4db3f32d21fa43c15032/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7370617469652f6c61726176656c2d75726c2d7369676e65722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/spatie/laravel-url-signer)[![Quality Score](https://camo.githubusercontent.com/a422121e07719a86bf117550515fba8527cf27eda0cd1f356c36ceb9adc13977/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7370617469652f6c61726176656c2d75726c2d7369676e65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/spatie/laravel-url-signer)[![Total Downloads](https://camo.githubusercontent.com/2c203c584f6e7c7b4229118b407e691f6b944cc6064d5d611092fdad9c8bfdf7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d75726c2d7369676e65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-url-signer)

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

The difference with [Laravel's native route signing](https://laravel.com/docs/master/urls#signed-urls) is that using this package:

- you can easily use signed URLs between different apps
- the signing secret used is not tied to the app key
- you can easily sign any URL (and not only a route belonging to your app)

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

```
use Spatie\UrlSigner\Laravel\Facades\UrlSigner;

UrlSigner::sign('https://myapp.com/protected-route', now()->addDays(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.

```
// returns `true` if the signed URL is valid, `false` if not
UrlSigner::validate('https://app.com/protected-route?expires=xxxxxx&signature=xxxxxx');
```

The package also provides [a middleware to protect routes](https://github.com/spatie/laravel-url-signer#protecting-routes-with-middleware).

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/f41278eb0001f1a0c07e73df29561164a8358953ca1e123301fb1a9b8d3e5726/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d75726c2d7369676e65722e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-url-signer)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

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](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

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

```
composer require spatie/laravel-url-signer
```

You must set an environment variable called `URL_SIGNER_SIGNATURE_KEY` and set it to a long secret value. This value will be used to sign and validate signed URLs.

```
php artisan generate:url-signer-signature-key
        {--s|show : Display the key instead of modifying files.}
        {--always-no : Skip generating key if it already exists.}
        {--f|force : Skip confirmation when overwriting an existing key.}

```

The configuration file can optionally be published via:

```
php artisan vendor:publish --tag="url-signer-config"
```

This is the content of the file:

```
return [
    /*
    * This string is used the to generate a signature. You should
    * keep this value secret.
    */
    'signature_key' => env('URL_SIGNER_SIGNATURE_KEY'),

    /*
     * The default expiration time of a URL in seconds.
     */
    'default_expiration_time_in_seconds' => 60 * 60 * 24,

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

Usage
-----

[](#usage)

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

```
use Spatie\UrlSigner\Laravel\Facades\UrlSigner;

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 lifetime, you can specify the number of days the URL should be valid:

```
use Spatie\UrlSigner\Laravel\Facades\UrlSigner;

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

// alternatively you could also pass the amount of seconds
UrlSigner::sign('https://myapp.com/protected-route', 60 * 5);
```

### Validating URLs

[](#validating-urls)

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

```
use Spatie\UrlSigner\Laravel\Facades\UrlSigner;

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

### Protecting routes with middleware

[](#protecting-routes-with-middleware)

The package provides a middleware to protect routes.

To use it you must first register the `Spatie\UrlSigner\Laravel\Middleware\ValidateSignature` as route middleware in your HTTP kernel.

```
// in app/Http/Kernel.php

protected $routeMiddleware = [
    // ...
    'signed-url' => \Spatie\UrlSigner\Laravel\Middleware\ValidateSignature::class,
];
```

Next, you can apply it on any route you want.

```
Route::get('protected-route', fn () => 'Hello secret world!')
    ->middleware('signed-url');
```

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

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

You can run the test using this command:

```
composer test
```

Usage outside Laravel
---------------------

[](#usage-outside-laravel)

If you're working on a non-Laravel project, you can use the [framework agnostic version](https://github.com/spatie/url-signer).

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you've found a bug regarding security please mail  instead of using the issue tracker.

Postcardware
------------

[](#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](https://spatie.be/en/opensource/postcards).

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [Sebastian De Deyne](https://github.com/sebastiandedeyne)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

68

—

FairBetter than 100% of packages

Maintenance83

Actively maintained with recent releases

Popularity60

Solid adoption and visibility

Community31

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 66.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~174 days

Recently: every ~283 days

Total

23

Last Release

85d ago

Major Versions

1.1.3 → 2.0.02017-02-09

2.7.0 → 3.0.02022-11-12

PHP version history (5 changes)1.0.0PHP &gt;=5.5.0

2.0.0PHP ^7.0

2.3.0PHP ^7.2

2.6.1PHP ^7.2|^8.0

3.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (118 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (24 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (10 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (8 commits)")[![NoahNxT](https://avatars.githubusercontent.com/u/58152024?v=4)](https://github.com/NoahNxT "NoahNxT (4 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (4 commits)")[![akoepcke](https://avatars.githubusercontent.com/u/5311185?v=4)](https://github.com/akoepcke "akoepcke (2 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (2 commits)")[![jeff-h](https://avatars.githubusercontent.com/u/841871?v=4)](https://github.com/jeff-h "jeff-h (2 commits)")[![adriaanzon](https://avatars.githubusercontent.com/u/4326420?v=4)](https://github.com/adriaanzon "adriaanzon (1 commits)")[![d13r](https://avatars.githubusercontent.com/u/236616?v=4)](https://github.com/d13r "d13r (1 commits)")[![jbrooksuk](https://avatars.githubusercontent.com/u/246103?v=4)](https://github.com/jbrooksuk "jbrooksuk (1 commits)")[![Omranic](https://avatars.githubusercontent.com/u/406705?v=4)](https://github.com/Omranic "Omranic (1 commits)")

---

Tags

laravelmailphpsecurityurlspatielaravel-url-signer

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/spatie-laravel-url-signer/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-laravel-url-signer/health.svg)](https://phpackages.com/packages/spatie-laravel-url-signer)
```

###  Alternatives

[spatie/laravel-backup

A Laravel package to backup your application

6.0k21.8M191](/packages/spatie-laravel-backup)[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M51](/packages/spatie-laravel-responsecache)[spatie/laravel-activitylog

A very simple activity logger to monitor the users of your website or application

5.8k45.4M309](/packages/spatie-laravel-activitylog)[spatie/laravel-query-builder

Easily build Eloquent queries from API requests

4.4k26.9M220](/packages/spatie-laravel-query-builder)[spatie/laravel-health

Monitor the health of a Laravel application

86910.0M83](/packages/spatie-laravel-health)[spatie/laravel-sitemap

Create and generate sitemaps with ease

2.6k14.6M107](/packages/spatie-laravel-sitemap)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
