Skip to content

Commit

Permalink
[Security] Document the LogoutRouteLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
MatTheCat committed Oct 6, 2023
1 parent c276932 commit e6bd0f9
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,53 @@ To enable logging out, activate the ``logout`` config parameter under your fire
;
};
Next, you need to create a route for this URL (but not a controller):
``path`` can be either a route name, or a URI.

Since Symfony 6.4, you can leverage the
:class:`Symfony\\Bundle\\SecurityBundle\\Routing\\LogoutRouteLoader`
to automatically register a route for every logout URI you configured.
If your project uses :ref:`Symfony Flex <symfony-flex>`,
this is already done for you.
Otherwise, you need to import the ``security.route_loader.logout`` service
as a routing resource:

.. configuration-block::

.. code-block:: yaml
# config/routes/security.yaml
logout:
resource: security.route_loader.logout
type: service
.. code-block:: xml
<!-- config/routes/security.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing
https://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="security.route_loader.logout" type="service"/>
</routes>
.. code-block:: php
// config/routes/security.php
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
return static function (RoutingConfigurator $routes): void {
$routes->import('security.route_loader.logout', 'service');
};
.. versionadded:: 6.4

The :class:`Symfony\\Bundle\\SecurityBundle\\Routing\\LogoutRouteLoader` was
introduced in Symfony 6.4.

Another option is to create a route matching the name or URI you configured as
``path``. You don't have to associate a controller because it wouldn't be called:

.. configuration-block::

Expand Down

0 comments on commit e6bd0f9

Please sign in to comment.