Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
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
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
fabpot approved these changesOct 1, 2023
Member
fabpot commentedOct 1, 2023
Thank you@PhilETaylor. |
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()`
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading.Please reload this page.
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 functions
impersonation_exit_urlandimpersonation_exit_pathwhich 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=_exittype urls/paths.However, to switch TO a user, hand crafted urls with
?_switch_user=MYIDENTIFIERlikehttp://example.com/somewhere?_switch_user=thomasneed to be hand crafted currently.The problem
if we now go and change
_switch_userto be something else, like_want_to_be_this_userin 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_userbut can be anything like_want_to_be_this_useras per the docs)This new twig function can be used as such:
This would output
?_want_to_be_this_user=mikeor if the default parameter still used would be?_switch_user=mikeThe PR repurposes the existing code to generate the paths and is backward compatible.