-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security][DX] RFC: A simple way to do programmatic logout #40663
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
👍 We had the need for this recently on a project and the way we went about it was to implement |
That's a good idea. We've had to implement custom logic during logout process, so we had to research for 4h and dig through the source code to better understand how to do it. So we've implemented the |
Thank you for this issue. |
No it has not. Still no simple and reliable way to logout a user programmatically. |
@buffcode (or anyone in this issue), are you open to create a PR for this targeting 6.1? Seems like everyone likes this feature, so we now need someone to make it happen |
There is #41406 for this. |
Thank you for this issue. |
Let’s continue in #41406 |
… programmatic logout (johnkrovitch, chalasr) This PR was merged into the 6.2 branch. Discussion ---------- [Security] Add a method in the security helper to ease programmatic logout | Q | A | ------------- | --- | Branch? | 6.x | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | Fix #40663 | License | MIT | Doc PR | This PR aims to ease the programmatic login using the Security helper, to fix (#40663). A simple method has been added to the Security helper. Thanks ! Commits ------- e5e7d5e Make CSRF validation opt-in f41a184 Add CSRF protection f576173 [Security] Add a method in the security helper to ease programmatic logout (#40663)
Description
There are various reasons why an app may need to logout a user without the user having to be redirected to the logout page, and currently there is no easy way to do this without copying some code from core which is subject to change and thus may leave one with outdated logic.
Example
Related to #40662, IMO a great API to have would be
Security
::programmaticLogout(Request $request)
This would figure out which firewall is relevant for the given $request, and trigger a logout event on that firewall's event dispatcher.
Why?
By digging through internals, it appears the best way to do this is the following:
This is copied from
symfony/src/Symfony/Component/Security/Http/Firewall/LogoutListener.php
Lines 121 to 131 in f963ae4
On top of that, some added complexity one has to figure out is that the event dispatcher here isn't just any event dispatcher, but you have to inject the correct event dispatcher for the firewall you want to do the logout on, and so you have to define that in the service yourself.. Firewall-specific event dispatchers are mentioned in passing in the docs but it's not exactly a common concept so this is all overall not great DX, and having an easy and more visible place to do this would be nice I think.
The text was updated successfully, but these errors were encountered: