Skip to content

Commit d7cf7b7

Browse files
committed
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.
1 parent 7f41dfb commit d7cf7b7

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

security/impersonating_user.rst

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

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

0 commit comments

Comments
 (0)