Question

I am doing a post from an external server to my Laravel app and it is throwing this exception on app/filters/policy.php: Illuminate\Session\TokenMismatchException.

This is my app/filters/policy.php:

Route::filter('csrf', function()
{
    $token = Request::ajax() ? Request::header('X-CSRF-Token') : Input::get('_token');

    if (Session::token() != $token)
    {
        throw new Illuminate\Session\TokenMismatchException;
    }
});

And this is my app/route.php:

Route::any('webservice', ['uses' => 'WebserverController@postWebservice']);

I think it is because the CSRF filter is applied to all routes, but I don't know how to disable it to /webservice.

I'd appreciate any help.

Was it helpful?

Solution

Maybe you may try something like this:

if(Request::url() != 'http://example.com//webservice') {
    $token = Request::ajax() ? Request::header('X-CSRF-Token') : Input::get('_token')
    if (Session::token() != $token) {
        throw new Illuminate\Session\TokenMismatchException;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top