You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug symfony#6881 Error in CSRF example code snippet (makoru-hikage)
This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closessymfony#6881).
Discussion
----------
Error in CSRF example code snippet
Something's wrong when I tried this code:
```
$session = new Session();
$csrfGenerator = new UriSafeTokenGenerator();
$csrfStorage = new SessionTokenStorage($session);
$csrfManager = new CsrfTokenManager($csrfGenerator, $csrfStorage);
$formFactory = Forms::createFormFactoryBuilder()
// ...
->addExtension(new CsrfExtension($csrfStorage))
->getFormFactory();
```
Constructing a `CsrfExtension` requires a `CsrfTokenManagerInterface` as an argument (see symfony/form/Extension/Csrf/CsrfExtension.php, line 47).
The `$csrfStorage` in `addExtension(new CsrfExtension($csrfStorage)`, has a class that implements `TokenStorageInterface` (see symfony/security-csrf/TokenStorage/SessionStorageToken.php, line 22).
So I replaced it with `$csrfManager` that has class that implements `CsrfTokenManagerInterface`. (see symfony/security-csrf/CsrfTokenManager.php, line 24)
Commits
-------
80c09dd Error in CSRF example code snippet
0 commit comments