URLGenerator signed route not working as expected
- Dominant language
- PHP
- Stars
- 9.4k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
| Q | A
| ----------------- | ---
| Bug? | yes
| New Feature? | yes
| Framework | Laravel
| Framework version | 5.6
| Package version | 2.0.0-alpha2
| PHP version | 7.2.6
#### Actual Behaviour
First i tried using the Laravel signed URL feature with `QUEUE_DRIVER` set to `sync` and its working fine, like this code below:
```php
URL::temporarySignedRoute('route.name')
```
But when I change it my `QUEUE_DRIVER` to `redis` I got an issue saying Route 'route.name' is not defined.
so instead of using the normal `URL` facade of Laravel, I used something like this:
```php
app('api.url')->version('v1')->temporarySignedRoute('route.name');
```
now the error is showing that the `keyResolver` is set to `NULL`. So I check how Laravel registered their `Illuminate\Routing\UrlGenerator` and found this in`Illuminate\Routing\RoutingServiceProvider`
Click [here](https://github.com/illuminate/routing/blob/master/RoutingServiceProvider.php#L72) to see the code
```php
$url->setKeyResolver(function () {
return $this->app->make('config')->get('app.key');
});
```
#### Expected Behaviour
It should allow me to successfully make a signed URL
```php
app('api.url')->version('v1')->signedRoute('route.name');
app('api.url')->version('v1')->temporarySignedRoute('route.name');
```
#### Steps to Reproduce
Just create a mail class like this having your URL link for the email and set your `QUEUE_DRIVER` to anything aside from `sync` in my end I used `redis`:
```php
class SendEmail extends Mailable implements ShouldQueue
{
...
public function url()
{
return app('api.url')->version('v1')->temporarySignedRoute('route.name');
}
```
#### Possible Solutions
Just insert this code in the `Dingo\Api\Provider\RoutingServiceProvider`
in [line 55](https://github.com/dingo/api/blob/master/src/Provider/RoutingServiceProvider.php#L55
):
```php
$url->setKeyResolver(function () {
return config('app.key');
});
```
and it should successfully create the signed URL you want
Contributor guide
Research direction
Inspect src/Provider/RoutingServiceProvider.php around line 55 and compare it with Laravel's Illuminate\Routing\RoutingServiceProvider linked in the report. Reproduce signed and temporary signed URL generation through app('api.url')->version('v1') from a queued Mailable using a non-sync queue driver. Done means both URL methods work without a null keyResolver.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- laravel, php
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100