spatie/laravel-url-signer

ErrorException in BaseUrlSigner.php line 44: The signature key is empty (View: plan.blade.php)

studiovlijmscherp opened this issue · 10 comments

laravel-url-signer is working perfectly fine on my local dev machine. When accessing url-signer on production i get

ErrorException in BaseUrlSigner.php line 44: The signature key is empty (View: plan.blade.php)

signature key is set in config/laravel-url-signer.php:
'signatureKey' => config('app.key'),

app.key is set:
'key' => env('APP_KEY'),

APP_KEY is set in .env:
APP_KEY=base64:pCeC0it .... .... ....

Edit: nevermind this post

Hmm this is a tough one. Laravel started to prefix APP_KEYS with base64: a little while ago, and this package internally uses a : as a delimeter for the sections in the unencoded query string.

For now, I'd recommend using a different key as the signatureKey, that doesn't include a colon. I can't push a quick fix since it would break all existing signed URL's, I'll give this some thought next week.

Unfortunately this doesn't seem to work. Changed the key to 32 char string, still no luck.
Strangely everything works on my local machine.

Locally running PHP 5.5.34 (cli) (built: Apr 22 2016 19:16:58)
Server running PHP 5.5.37 (cli) (built: Jul 7 2016 22:33:48)

Both using SQLite

Looks like the config values simply aren't being set on the server then. I'd start by logging the values in the service provider: https://github.com/spatie/laravel-url-signer/blob/master/src/UrlSignerServiceProvider.php#L43

Maybe open a tinker session to see what's in config('laravel-url-signer'); first.

well... okay... seems logical why it can't find the signatureKey...

=> [
     "signatureKey" => null,
     "default_expiration_time_in_days" => 30,
     "parameters" => [
       "expires" => "expires",
       "signature" => "signature",
     ],
   ]

Why would this be happening? I have the same .env and config files on both live and production.

Logging the values doesn't work. Errors occur before even getting there.

Have you found the solution to this yet? My first thought would be that there aren't any env variables being read, can you confirm that other ones are indeed working in production?

Yes, other ENV variables are being read (like the DB_CONNECTION). I can also echo out all the .env variables (including the APP_KEY)

I added an new custom key to laravel-url-signer.php, the signer does seem to work now.
The config('app.key') clearly cannot be found somehow.

Had the same problem. Changed it to 'signatureKey' => env('APP_SIGNATURE_KEY') and added APP_SIGNATURE_KEY to .env file.

I think the issue is that the config/url-signer.php contains a reference to config('app.key'). See https://blog.maqe.com/dont-use-laravel-s-config-inside-config-files-40e2c8207225.

PR to fix this — #25