Skip to content

Commit 162ce75

Browse files
committed
Rewording
1 parent e6bd0f9 commit 162ce75

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

security.rst

+30-23
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,7 @@ To enable logging out, activate the ``logout`` config parameter under your fire
17961796
main:
17971797
# ...
17981798
logout:
1799-
path: app_logout
1799+
path: /logout
18001800
18011801
# where to redirect after logout
18021802
# target: app_any_route
@@ -1817,8 +1817,7 @@ To enable logging out, activate the ``logout`` config parameter under your fire
18171817
<!-- ... -->
18181818
18191819
<firewall name="main">
1820-
<!-- ... -->
1821-
<logout path="app_logout"/>
1820+
<logout path="/logout"/>
18221821
18231822
<!-- use "target" to configure where to redirect after logout
18241823
<logout path="app_logout" target="app_any_route"/>
@@ -1838,30 +1837,28 @@ To enable logging out, activate the ``logout`` config parameter under your fire
18381837
$mainFirewall = $security->firewall('main');
18391838
// ...
18401839
$mainFirewall->logout()
1841-
// the argument can be either a route name or a path
1842-
->path('app_logout')
1840+
->path('/logout')
18431841
18441842
// where to redirect after logout
18451843
// ->target('app_any_route')
18461844
;
18471845
};
18481846
1849-
``path`` can be either a route name, or a URI.
1847+
Symfony will then un-authenticate users navigating to the configured ``path``,
1848+
and redirect them to the configured ``target``.
18501849

1851-
Since Symfony 6.4, you can leverage the
1852-
:class:`Symfony\\Bundle\\SecurityBundle\\Routing\\LogoutRouteLoader`
1853-
to automatically register a route for every logout URI you configured.
1854-
If your project uses :ref:`Symfony Flex <symfony-flex>`,
1855-
this is already done for you.
1856-
Otherwise, you need to import the ``security.route_loader.logout`` service
1857-
as a routing resource:
1850+
If your project uses :ref:`Symfony Flex <symfony-flex>`, you're all set:
1851+
the :class:`Symfony\\Bundle\\SecurityBundle\\Routing\\LogoutRouteLoader` will
1852+
automatically register a route for every logout URI you configured!
1853+
Otherwise, you can enable this behavior yourself by importing the
1854+
``security.route_loader.logout`` service as a routing resource:
18581855

18591856
.. configuration-block::
18601857

18611858
.. code-block:: yaml
18621859
18631860
# config/routes/security.yaml
1864-
logout:
1861+
_symfony_logout:
18651862
resource: security.route_loader.logout
18661863
type: service
18671864
@@ -1891,8 +1888,10 @@ as a routing resource:
18911888
The :class:`Symfony\\Bundle\\SecurityBundle\\Routing\\LogoutRouteLoader` was
18921889
introduced in Symfony 6.4.
18931890

1894-
Another option is to create a route matching the name or URI you configured as
1895-
``path``. You don't have to associate a controller because it wouldn't be called:
1891+
Another option is to configure ``path`` as a route name, which can be useful if
1892+
you want logout URIs to be translated according to the current locale e.g.
1893+
In that case, you have to create this route yourself.
1894+
Note that it doesn't need a controller, because it wouldn't be called anyways:
18961895

18971896
.. configuration-block::
18981897

@@ -1906,7 +1905,10 @@ Another option is to create a route matching the name or URI you configured as
19061905
19071906
class SecurityController extends AbstractController
19081907
{
1909-
#[Route('/logout', name: 'app_logout', methods: ['GET'])]
1908+
#[Route([
1909+
'en' => '/logout',
1910+
'fr' => '/deconnexion'
1911+
], name: 'app_logout', methods: ['GET'])]
19101912
public function logout(): never
19111913
{
19121914
// controller can be blank: it will never be called!
@@ -1918,7 +1920,9 @@ Another option is to create a route matching the name or URI you configured as
19181920
19191921
# config/routes.yaml
19201922
app_logout:
1921-
path: /logout
1923+
path:
1924+
en: /logout
1925+
fr: /deconnexion
19221926
methods: GET
19231927
19241928
.. code-block:: xml
@@ -1930,7 +1934,10 @@ Another option is to create a route matching the name or URI you configured as
19301934
xsi:schemaLocation="http://symfony.com/schema/routing
19311935
https://symfony.com/schema/routing/routing-1.0.xsd">
19321936
1933-
<route id="app_logout" path="/logout" methods="GET"/>
1937+
<route id="app_logout" path="/logout" methods="GET">
1938+
<path locale="en">/logout</path>
1939+
<path locale="fr">/deconnexion</path>
1940+
</route>
19341941
</routes>
19351942
19361943
.. code-block:: php
@@ -1939,14 +1946,14 @@ Another option is to create a route matching the name or URI you configured as
19391946
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
19401947
19411948
return function (RoutingConfigurator $routes): void {
1942-
$routes->add('app_logout', '/logout')
1949+
$routes->add('app_logout', [
1950+
'en' => '/logout',
1951+
'fr' => '/deconnexion',
1952+
])
19431953
->methods(['GET'])
19441954
;
19451955
};
19461956
1947-
That's it! By sending a user to the ``app_logout`` route (i.e. to ``/logout``)
1948-
Symfony will un-authenticate the current user and redirect them.
1949-
19501957
Logout programmatically
19511958
~~~~~~~~~~~~~~~~~~~~~~~
19521959

0 commit comments

Comments
 (0)