简体   繁体   English

如何使用CSRF令牌发布到Laravel API?

[英]How to POST to Laravel API with CSRF Token?

I am creating an API using laravel and I noticed that when trying to create a form for POST, I need to use csrf token. 我正在使用laravel创建API,我注意到尝试为POST创建表单时,需要使用csrf令牌。 However, I will be using this API for a mobile app. 但是,我将针对移动应用程序使用此API。 How do I post to laravel with a token? 如何使用令牌向laravel发布? Do I have to fetch it in laravel first or should I just place an exception in the middleware? 我必须首先在laravel中获取它还是应该在中间件中放置一个例外?

If I should be using the csrf token, does it expire? 如果我应该使用csrf令牌,它会过期吗? How long does it last? 持续多长时间?

You should use other authentication ways. 您应该使用其他身份验证方式。 OAuth, JWT... Laravel passport is a powerful way to do that. OAuth,JWT ... Laravel护照是一种有效的方法。 A service for mobile app, specially mobile app, will need those authentication types. 用于移动应用程序(特别是移动应用程序)的服务将需要这些身份验证类型。 CSRF Token is working a lil bit different way CSRF令牌的工作方式略有不同

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM