Laravel and Dropbox WebAuth: “Missing CSRF token in session”

天大地大妈咪最大 提交于 2019-12-05 12:43:12
Blaatpraat

Why reinvent the wheel, if you have a wrapper that can do this for you:

https://github.com/GrahamCampbell/Laravel-Dropbox

The reason is that the POST routes are protected with CSRF. If you do not want to use a wrapper, you need to disable this security layer, but nobody would recommend that.

Even better is using Laravel Socialite. Only the fact is here that Dropbox is not natively supported in it, but this package will solve that.

Credits to ceejayoz for helping with this!

Note: Using a Dropbox package as in @Blaatpraat's answer is generally a better idea than this. If you're dead-set on using your own logic, though:

Laravel 5 POST routes (Dropbox is posting back to you at the end of the process) are protected by default by the CSRF protection middleware. Because Dropbox doesn't know your Laravel app's CSRF token (nor does it know to send one), the _token parameter is missing and fails the middleware.

You'll need to modify app/Http/Middleware/VerifyCsrfToken.php to exempt this route. Where it says:

return parent::handle($request, $next);

You'll want something like this to bypass the CSRF check on certain routes:

if(\Request::is('finish') { return $next($request); }
return parent::handle($request, $next);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!