8000 4668 document isCsrfTokenValid by snoek09 · Pull Request #5572 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content

4668 document isCsrfTokenValid #5572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
4668 show non-shortcut alternative, use variable argument for submitt…
…ed token
  • Loading branch information
Henry Snoek committed Jul 28, 2015
commit 91b3f99159508115e4a6c0b9e75bf455f2c866b9
11 changes: 10 additions & 1 deletion book/controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -811,10 +811,19 @@ Symfony form.

If, for example, you're doing a DELETE action, you can use ``isCsrfTokenValid()``::

if ($this->isCsrfTokenValid('token_id', 'TOKEN')) {
if ($this->isCsrfTokenValid('token_id', $submittedToken)) {
// ... do something, like deleting an object
}

.. versionadded:: 2.6
The ``isCsrfTokenValid()`` shortcut method was added in Symfony 2.6.

Previously you would use::

use Symfony\Component\Security\Csrf\CsrfToken;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this code listing be indented?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will do after the merge


$this->get('security.csrf.token_manager')->isTokenValid(new CsrfToken('token_id', 'TOKEN'));

Final Thoughts
--------------

Expand Down
0