Created
February 19, 2015 10:47
-
-
Save yesdevnull/3f9ee445c5838add8905 to your computer and use it in GitHub Desktop.
Using X-XSRF-TOKENs for AJAX in Laravel 5 - Option 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier; | |
use Symfony\Component\Security\Core\Util\StringUtils; | |
class VerifyCsrfToken extends BaseVerifier { | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
return parent::handle($request, $next); | |
} | |
protected function tokensMatch($request) | |
{ | |
$token = $request->session()->token(); | |
$header = $request->header('X-XSRF-TOKEN'); | |
return StringUtils::equals($token, $request->input('_token')) || | |
($header && StringUtils::equals($token, $header)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- ... --> | |
<head> | |
<meta name="csrf_token" content="{{ csrf_token() }}" /> | |
</head> | |
<!-- .. --> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good job!
But I found some thing at original tokensMatch().Could we should decrypt the $header?