Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package breaks signed out/temporary signed route url generation #14

Open
mnazmi23 opened this issue Apr 11, 2020 · 2 comments
Open

Package breaks signed out/temporary signed route url generation #14

mnazmi23 opened this issue Apr 11, 2020 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@mnazmi23
Copy link

Hi,

I had to uninstall this lovely package. I came from Mcmara localization package and this package just works out of the box, including the URL translation.

I have been using it for the past weeks, adding translations and stuff, until the testing part for using the signed route url. I spent 2 days troubleshooting this issue, until I tried uninstalling this package, and my app works again(for the url creation part).

Step to reproduce, try using the email resend feature included by laravel. I got the error
call_user_func() expects parameter 1 to be a valid callback, no array or string given

Upon inspection, the error came from Illuminate/Routing/URLGenerator class, in this function,

` public function hasCorrectSignature(Request $request, $absolute = true)
{
$url = $absolute ? $request->url() : '/'.$request->path();

    $original = rtrim($url.'?'.Arr::query(
        Arr::except($request->query(), 'signature')
    ), '?');

    $signature = hash_hmac('sha256', $original, call_user_func($this->keyResolver));

    return hash_equals($signature, (string) $request->query('signature', ''));
}` 

This part ==>> call_user_func($this->keyResolver)) has the value null in it. When I tried commenting some of the lines in here, the email resend feature works again.

Turns out your package has URLGenerator file and extending the LaravelUrlGenerator in it. I think there is some thing missing in your code.

This is the log,
call_user_func() expects parameter 1 to be a valid callback, no array or string given {"exception":"[object] (ErrorException(code: 0): call_user_func() expects parameter 1 to be a valid callback, no array or string given at C:\\project\\app\\portal-x\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\UrlGenerator.php:337)

@mabasic
Copy link
Member

mabasic commented Apr 12, 2020

Hi, thank you for letting me know the issue. I'm sorry that you spent two days debugging it...

I could probably solve the issue by updating that part of the code to match the latest Laravel version, but... after using this package myself for some time now I came to a conclusion that there must be an even simpler way of implementing it...

My idea, which I failed to implement once, was to extend the Laravel Route with extra methods and properties which would hold the locale data and translated URLs. Something like:

Route::view('/about')->locales([
    'hr' => 'o-nama',
    'de'
]);

This would mean that the default locale (let us say it is en, as written in app.php) is /about, the hr url is translated and is /o-nama, and the de locale is /de/about. That route supports three locales then: en, hr and de. Two have translated urls (en, hr), and one doesn't(de).

Or

Route::view('/about')->locale('hr', 'o-nama')->locale('de');

@mabasic mabasic self-assigned this Apr 12, 2020
@mabasic mabasic added the bug Something isn't working label Apr 12, 2020
@mnazmi23
Copy link
Author

THank you for acknowledging this. Hoping to use this package again soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants