Hi guys,
I'm trying to verify a CSRF token and it's always failing.. I'm using AngularJS on the client side and making calls to the server via AJAX. I don't think I'm doing anything 'unusual'.... At first I tried to set the token directly in the headers by default, but that didn't work at all, so I figured I'd try to automatically add it to each POST request I'm making, but it's still not working.
In my index.phtml:
<meta name="csrf_token_name" content="<?php echo $this->security->getTokenKey() ?>">
<meta name="csrf_token" content="<?php echo $this->security->getToken() ?>">
In my controller:
$token = $this->request->getPost("CSRFTokenName");
$tokenKey = $this->request->getPost("CSRFToken");
$validToken = $this->security->checkToken($tokenKey, $token);
if (!$this->request->isPost() || !$validToken) {
$response->setContent(json_encode(array('success'=>false)));
return $response;
}
My request does have CSRFTokenName nad CSRFToken in it.
And no, I didn't forget to set the session in DI:
$di->setShared('session', function () {
$session = new Phalcon\Session\Adapter\Files();
$session->start();
return $session;
});
$validToken always returns false. I'm wondering what I'm doing wrong?
Thanks!