Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add new twig bridge function to generate impersonation path#50030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:6.4fromPhilETaylor:6.3-impoersonation
Oct 1, 2023

Conversation

@PhilETaylor
Copy link
Contributor

@PhilETaylorPhilETaylor commentedApr 16, 2023
edited
Loading

QA
Branch?6.3
Bug fix?no
New feature?yes
Deprecations?no
LicenseMIT
Doc PRsymfony/symfony-docs#...

Before this PR

So we already have impersonation features in Symfony (https://symfony.com/doc/current/security/impersonating_user.html) and we have two twig helper functionsimpersonation_exit_url andimpersonation_exit_path which both work with the configuration parameter for the switch user.

If the developer changes the switch parameter (_switch_user), then these helper functions will dynamically update the_switch_user=_exit type urls/paths.

However, to switch TO a user, hand crafted urls with?_switch_user=MYIDENTIFIER likehttp://example.com/somewhere?_switch_user=thomas need to be hand crafted currently.

The problem

if we now go and change_switch_user to be something else, like_want_to_be_this_user in the Symfony configuration (Because the boss told us to do that), then all our exit path/urls will dynamically update, but our hard coded ?_switch_user=MYIDENTIFIER` will stop working.

The solution this PR provides

The solution this PR provides is to provide a new Twig Helper function for the impersonation path only, taking into account the configured value in Symfony config of the parameter (default is still_switch_user but can be anything like_want_to_be_this_user as per the docs)

This new twig function can be used as such:

<ahref="{{ impersonation_path('mike') }}">Impersonate Mike</a>

This would output?_want_to_be_this_user=mike or if the default parameter still used would be?_switch_user=mike

The PR repurposes the existing code to generate the paths and is backward compatible.

OskarStark and ker0x reacted with thumbs up emoji
@fabpot
Copy link
Member

Thank you@PhilETaylor.

@fabpotfabpot merged commit6ef8975 intosymfony:6.4Oct 1, 2023
fabpot added a commit that referenced this pull requestOct 2, 2023
…ory and add `impersonation_url()` (alexandre-daubois)This PR was merged into the 6.4 branch.Discussion----------[Security] Make `impersonation_path()` argument mandatory and add `impersonation_url()`| Q             | A| ------------- | ---| Branch?       | 6.4| Bug fix?      | yes| New feature?  | yes| Deprecations? | no| Tickets       | -| License       | MITFollow-up of#50030When documenting this function, I found out that the`identifier` argument was optional, which seemed weird to me given the function purpose.I then had a look at the implementation, and I saw that `ImpersonateUrlGenerator::generateImpersonationPath()` accepts a nullable string. However, the underlying call to `ImpersonateUrlGenerator::buildPath()` doesn't accept a nullable string. I propose to make the `identifier` argument mandatory, which makes more sense here.I also added the missing Changelog line and `impersonation_url()`Commits-------5d71d95 [Security] Make `impersonation_path()` argument mandatory and add `impersonation_url()`
This was referencedOct 21, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@wouterjwouterjAwaiting requested review from wouterj

@chalasrchalasrAwaiting requested review from chalasrchalasr is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

6.4

Development

Successfully merging this pull request may close these issues.

4 participants

@PhilETaylor@fabpot@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp