Closed madsem closed 5 years ago
I have...
public function __invoke($request, $response, $next)
{
$this->container->view->getEnvironment()->addGlobal('csrf', [
'field' => '
<input type="hidden" name="' . $this->container->csrf->getTokenNameKey() . '" value="' . $this->container->csrf->getTokenName() . '">
<input type="hidden" name="' . $this->container->csrf->getTokenValueKey() . '" value="' . $this->container->csrf->getTokenValue() . '">
',
]);
$response = $next($request, $response);
return $response;
}
and I get in my TWIG template...
<input type="hidden" name="csrf_name" value="">
<input type="hidden" name="csrf_value" value="">
But if I drop $this->container->csrf->getTokenValueKey() into my AuthController::getSignIn() it gives me a value!
very very odd
Fixes easy with changing middleware order: Add your csrf middleware before adding csrf test. Looks like after checking name and value clears. Example (in middleware.php):
$app->add(new \Src\Middleware\CsrfRendererMiddleware($container));
$app->add($container->get('csrf'));
No matter what I try the getTokenName() & getTokenValue() methods always return null.
I copied and pasted the CsrfExtension straight from the the docs. Registered in my ViewServiceProvider and passed CsrfExtension the container instance of Guard.
If I do this though inside the CsrfExtension, I get key and value:
Outputs:
Is there anything wrong with doing it this way?
I'm just really curious why the other methods aren't working... Tried sifting through the source but am really unsure why this isn't working