仅针对单个方法删除CSRF令牌-Laravel [英] Remove csrf token only for single method - Laravel
问题描述
我正在使用paytabs付款网关api.在该api中,必须提供重定向网址,以便在交易完成后,页面将自动重定向到您指定的重定向网址.该网址是一个GET网址,但是由于api的响应是POST类型的,因此我无法使用get网址.为了解决该问题,我将该路由设置为POST URL,但是通过将其设置为post方法,则没有获得任何CSRF令牌.最后,我遇到了这个问题.
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:
有什么方法可以使CSRF令牌功能仅针对单个POST网址?
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',
];
}
现在得到
Class 'Middleware' not found
推荐答案
来自文档:
通常,您应该将这些类型的路由放置在RouteServiceProvider应用于
routes/web.php
文件中的所有路由的Web中间件组之外.但是,您也可以通过将路由的URI添加到VerifyCsrfToken
中间件的$ except属性中来排除路由:
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 theVerifyCsrfToken
middleware:
class VerifyCsrfToken extends Middleware
{
protected $except = [
'stripe/*',
'http://example.com/foo/bar',
'http://example.com/foo/*',
];
}
这篇关于仅针对单个方法删除CSRF令牌-Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!