Skip to content

Commit 21e8d67

Browse files
authored
Update impersonating_user.rst
To use switching user feature via `HTTP_X_SWITCH_USER` header we have to set `switch_user.parameter: HTTP_X_SWITCH_USER` in security.yaml. refs: symfony/symfony#39907
1 parent cc94197 commit 21e8d67

File tree

1 file changed

+49
-1
lines changed

1 file changed

+49
-1
lines changed

security/impersonating_user.rst

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,55 @@ as the value to the current URL:
7676
.. tip::
7777

7878
Instead of adding a ``_switch_user`` query string parameter, you can pass
79-
the username in a ``HTTP_X_SWITCH_USER`` header.
79+
the username in a ``HTTP_X_SWITCH_USER`` header. You can use this feature by adjusting the ``parameter`` setting:
80+
81+
.. configuration-block::
82+
83+
.. code-block:: yaml
84+
85+
# config/packages/security.yaml
86+
security:
87+
# ...
88+
89+
firewalls:
90+
main:
91+
# ...
92+
switch_user: { parameter: HTTP_X_SWITCH_USER }
93+
94+
.. code-block:: xml
95+
96+
<!-- config/packages/security.xml -->
97+
<?xml version="1.0" encoding="UTF-8" ?>
98+
<srv:container xmlns="http://symfony.com/schema/dic/security"
99+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
100+
xmlns:srv="http://symfony.com/schema/dic/services"
101+
xsi:schemaLocation="http://symfony.com/schema/dic/services
102+
https://symfony.com/schema/dic/services/services-1.0.xsd
103+
http://symfony.com/schema/dic/security
104+
https://symfony.com/schema/dic/security/security-1.0.xsd">
105+
<config>
106+
<!-- ... -->
107+
108+
<firewall name="main">
109+
<!-- ... -->
110+
<switch-user parameter="HTTP_X_SWITCH_USER"/>
111+
</firewall>
112+
</config>
113+
</srv:container>
114+
115+
.. code-block:: php
116+
117+
// config/packages/security.php
118+
use Symfony\Config\SecurityConfig;
119+
120+
return static function (SecurityConfig $security) {
121+
// ...
122+
$security->firewall('main')
123+
// ...
124+
->switchUser()
125+
->parameter('HTTP_X_SWITCH_USER')
126+
;
127+
};
80128
81129
To switch back to the original user, use the special ``_exit`` username:
82130

0 commit comments

Comments
 (0)