Files
spa-api/app/Http/Middleware/CsrfMiddleware.php

38 lines
777 B
PHP
Raw Normal View History

2014-10-06 15:25:53 -05:00
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Routing\Middleware;
use Illuminate\Session\TokenMismatchException;
class CsrfMiddleware implements Middleware {
/**
* Handle an incoming request.
*
2014-10-06 15:46:34 -05:00
* @param \Illuminate\Http\Request $request
2014-10-06 15:25:53 -05:00
* @param \Closure $next
2014-10-06 15:46:34 -05:00
* @return mixed
2014-10-06 15:25:53 -05:00
*/
public function handle($request, Closure $next)
{
2014-10-09 21:50:52 -05:00
if ($request->method == 'GET' || $this->tokensMatch($request))
2014-10-06 15:25:53 -05:00
{
2014-10-09 21:50:52 -05:00
return $next($request);
2014-10-06 15:25:53 -05:00
}
2014-10-09 21:50:52 -05:00
throw new TokenMismatchException;
}
/**
* Determine if the session and input CSRF tokens match.
*
* @param \Illuminate\Http\Request $request
* @return bool
*/
protected function tokensMatch($request)
{
2014-10-09 21:56:13 -05:00
return $request->session()->token() == $request->input('_token');
2014-10-06 15:25:53 -05:00
}
}