Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a18880a

Browse files
committed
minor #16405 [Security] Update impersonating_user.rst (ttskch)
This PR was merged into the 4.4 branch. Discussion ---------- [Security] 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 <!-- If your pull request fixes a BUG, use the oldest maintained branch that contains the bug (see https://symfony.com/releases for the list of maintained branches). If your pull request documents a NEW FEATURE, use the same Symfony branch where the feature was introduced (and `6.x` for features of unreleased versions). --> Commits ------- 38b42b8 Update impersonating_user.rst
2 parents 3ad5598 + 38b42b8 commit a18880a

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

security/impersonating_user.rst

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,52 @@ 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+
84+
# config/packages/security.yaml
85+
security:
86+
# ...
87+
firewalls:
88+
main:
89+
# ...
90+
switch_user: { parameter: HTTP_X_SWITCH_USER }
91+
92+
.. code-block:: xml
93+
94+
<!-- config/packages/security.xml -->
95+
<?xml version="1.0" encoding="UTF-8" ?>
96+
<srv:container xmlns="http://symfony.com/schema/dic/security"
97+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
98+
xmlns:srv="http://symfony.com/schema/dic/services"
99+
xsi:schemaLocation="http://symfony.com/schema/dic/services
100+
https://symfony.com/schema/dic/services/services-1.0.xsd
101+
http://symfony.com/schema/dic/security
102+
https://symfony.com/schema/dic/security/security-1.0.xsd">
103+
<config>
104+
<!-- ... -->
105+
<firewall name="main">
106+
<!-- ... -->
107+
<switch-user parameter="HTTP_X_SWITCH_USER"/>
108+
</firewall>
109+
</config>
110+
</srv:container>
111+
112+
.. code-block:: php
113+
114+
// config/packages/security.php
115+
use Symfony\Config\SecurityConfig;
116+
return static function (SecurityConfig $security) {
117+
// ...
118+
$security->firewall('main')
119+
// ...
120+
->switchUser()
121+
->parameter('HTTP_X_SWITCH_USER')
122+
;
123+
};
79124
80125
To switch back to the original user, use the special ``_exit`` username:
81126

0 commit comments

Comments
 (0)