@@ -768,6 +768,60 @@ Logging Out
768
768
769
769
To enable logging out, activate the ``logout `` config parameter under your firewall:
770
770
771
+ .. configuration-block ::
772
+
773
+ .. code-block :: yaml
774
+
775
+ # config/packages/security.yaml
776
+ security :
777
+ # ...
778
+
779
+ firewalls :
780
+ main :
781
+ # ...
782
+ logout : ~
783
+
784
+ .. code-block :: xml
785
+
786
+ <!-- config/packages/security.xml -->
787
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
788
+ <srv : container xmlns =" http://symfony.com/schema/dic/security"
789
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
790
+ xmlns : srv =" http://symfony.com/schema/dic/services"
791
+ xsi : schemaLocation =" http://symfony.com/schema/dic/services
792
+ https://symfony.com/schema/dic/services/services-1.0.xsd" >
793
+
794
+ <config >
795
+ <!-- ... -->
796
+
797
+ <firewall name =" secured_area" >
798
+ <!-- ... -->
799
+ <logout />
800
+ </firewall >
801
+ </config >
802
+ </srv : container >
803
+
804
+ .. code-block :: php
805
+
806
+ // config/packages/security.php
807
+ $container->loadFromExtension('security', [
808
+ // ...
809
+
810
+ 'firewalls' => [
811
+ 'secured_area' => [
812
+ // ...
813
+ 'logout' => [],
814
+ ],
815
+ ],
816
+ ]);
817
+
818
+
819
+ And that's it! By sending a user to ``/logout ``, Symfony will un-authenticate
820
+ the current user.
821
+
822
+ If you want to change the path from the default ``/logout `` to a custom url,
823
+ you need to set the `path ` option *and * setup a matching route like this:
824
+
771
825
.. configuration-block ::
772
826
773
827
.. code-block :: yaml
@@ -780,7 +834,7 @@ To enable logging out, activate the ``logout`` config parameter under your fire
780
834
main :
781
835
# ...
782
836
logout :
783
- path : app_logout
837
+ path : /my-logout
784
838
785
839
# where to redirect after logout
786
840
# target: app_any_route
@@ -800,7 +854,7 @@ To enable logging out, activate the ``logout`` config parameter under your fire
800
854
801
855
<firewall name =" secured_area" >
802
856
<!-- ... -->
803
- <logout path =" app_logout " />
857
+ <logout path =" /my-logout " />
804
858
</firewall >
805
859
</config >
806
860
</srv : container >
@@ -814,12 +868,12 @@ To enable logging out, activate the ``logout`` config parameter under your fire
814
868
'firewalls' => [
815
869
'secured_area' => [
816
870
// ...
817
- 'logout' => ['path' => 'app_logout '],
871
+ 'logout' => ['path' => '/my-logout '],
818
872
],
819
873
],
820
874
]);
821
875
822
- Next, you'll need to create a route for this URL (but not a controller):
876
+ Now you need to create a route for this URL (but not a controller):
823
877
824
878
.. configuration-block ::
825
879
@@ -834,7 +888,7 @@ Next, you'll need to create a route for this URL (but not a controller):
834
888
class SecurityController extends AbstractController
835
889
{
836
890
/**
837
- * @Route("/logout", name="app_logout", methods={"GET"})
891
+ * @Route("/my- logout", name="app_logout", methods={"GET"})
838
892
*/
839
893
public function logout()
840
894
{
@@ -847,7 +901,7 @@ Next, you'll need to create a route for this URL (but not a controller):
847
901
848
902
# config/routes.yaml
849
903
app_logout :
850
- path : /logout
904
+ path : /my- logout
851
905
methods : GET
852
906
853
907
.. code-block :: xml
@@ -859,7 +913,7 @@ Next, you'll need to create a route for this URL (but not a controller):
859
913
xsi : schemaLocation =" http://symfony.com/schema/routing
860
914
https://symfony.com/schema/routing/routing-1.0.xsd" >
861
915
862
- <route id =" app_logout" path =" /logout" methods =" GET" />
916
+ <route id =" app_logout" path =" /my- logout" methods =" GET" />
863
917
</routes >
864
918
865
919
.. code-block :: php
@@ -868,14 +922,11 @@ Next, you'll need to create a route for this URL (but not a controller):
868
922
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
869
923
870
924
return function (RoutingConfigurator $routes) {
871
- $routes->add('logout ', '/logout')
925
+ $routes->add('app_logout ', '/my- logout')
872
926
->methods(['GET'])
873
927
;
874
928
};
875
929
876
- And that's it! By sending a user to the ``app_logout `` route (i.e. to ``/logout ``)
877
- Symfony will un-authenticate the current user and redirect them.
878
-
879
930
.. tip ::
880
931
881
932
Need more control of what happens after logout? Add a ``success_handler `` key
0 commit comments