Remove csrf token only for single method - Laravel

蓝咒 提交于 2019-12-10 17:17:59

问题


I am using paytabs payment gateway api. In that api, a redirect url have to given, so that once the transaction is completed, the page will redirect automatically to your given redirect url. The url was a GET url but since the response of the api comes as a POST type, I was unable to use get url. To resolve that issue, I made that route a POST url but by making it post method, I am not getting any CSRF token. In the end, I get this issue.

TokenMismatchException in VerifyCsrfToken.php line 68:

Is there any way by which I could disbale CSRF token functionality for only single POST url?

--SUGGESTION TRIED-- I did this as per your suggestion

class VerifyCsrfToken extends Middleware
{
    protected $except = [
        'signup/complete',
    ];
}

and now getting

Class 'Middleware' not found

回答1:


From the docs:

Typically, you should place these kinds of routes outside of the web middleware group that the RouteServiceProvider applies to all routes in the routes/web.php file. However, you may also exclude the routes by adding their URIs to the $except property of the VerifyCsrfToken middleware:

class VerifyCsrfToken extends Middleware
{
    protected $except = [
        'stripe/*',
        'http://example.com/foo/bar',
        'http://example.com/foo/*',
    ];
}



回答2:


You can exception in csrf middleware. go to app/http/Middleware/VirefyCsrfToken.php

class VerifyCsrfToken extends BaseVerifier{
    protected $except = [
     'route url1',
     'route url2',

    ]
}



回答3:


for how use localhost in your project folder /app/http/middleware/VerifyCsrfToken.php edit

protected $except = [
    //
    'http://localhost/blog/return_url',  // your url
];


来源:https://stackoverflow.com/questions/48339630/remove-csrf-token-only-for-single-method-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!