Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

docs: add docs for programmatic logout#17328

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
wouterj merged 2 commits intosymfony:6.2fromjohnkrovitch:docs/programatic-logout
Oct 16, 2022
Merged
Changes fromall commits
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
39 changes: 39 additions & 0 deletionssecurity.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1723,6 +1723,45 @@ Next, you need to create a route for this URL (but not a controller):
That's it! By sending a user to the ``app_logout`` route (i.e. to ``/logout``)
Symfony will un-authenticate the current user and redirect them.

Logout programmatically
~~~~~~~~~~~~~~~~~~~~~~~

.. versionadded:: 6.2

The :class:`Symfony\Bundle\SecurityBundle\Security\Security <Symfony\\Bundle\\SecurityBundle\\Security\\Security>`
class was introduced in Symfony 6.2. Prior to 6.2, it was called
``Symfony\Component\Security\Core\Security``.

.. versionadded:: 6.2

The :method:`Symfony\\Bundle\\SecurityBundle\\Security\\Security::logout`
method was introduced in Symfony 6.2.

You can logout user programmatically using the ``logout()`` method of the
:class:`Symfony\\Bundle\\SecurityBundle\\Security\\Security` helper::

// src/Controller/SecurityController.php
namespace App\Controller\SecurityController;

use Symfony\Bundle\SecurityBundle\Security\Security;

class SecurityController
{
public function someAction(Security $security): Response
{
// logout the user in on the current firewall
$response = $security->logout();

// you can also disable the csrf logout
$response = $security->logout(false);

// ... return $response (if set) or e.g. redirect to the homepage
}
}

The user will be logout from the firewall of the request. If the request is
not behind a firewall a ``\LogicException`` will be thrown.

Customizing Logout
~~~~~~~~~~~~~~~~~~

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp