-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When you log in to the main DOMjudge, allow to use the API with the s…
…ame user
- Loading branch information
1 parent
e6c58ec
commit 080932d
Showing
3 changed files
with
28 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
24 changes: 24 additions & 0 deletions
24
webapp/src/EventListener/NoSessionCookieForApiListener.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace App\EventListener; | ||
|
||
use Symfony\Component\EventDispatcher\Attribute\AsEventListener; | ||
use Symfony\Component\HttpKernel\Event\ResponseEvent; | ||
|
||
// The AbstractSessionListener (which sets the cookie) has a priority of -1000, so we need to | ||
// set a priority of -1001 to run before it. | ||
#[AsEventListener(priority: -1001)] | ||
class NoSessionCookieForApiListener | ||
{ | ||
public function __invoke(ResponseEvent $event): void | ||
{ | ||
// We do not want to set the session cookie for API requests. Since the firewall is | ||
// stateful (because we want form logins to allow to access the API), we need to remove | ||
// the cookie | ||
$request = $event->getRequest(); | ||
$response = $event->getResponse(); | ||
if ($request->attributes->get('_firewall_context') === 'security.firewall.map.context.api') { | ||
$response->headers->removeCookie($request->getSession()->getName()); | ||
} | ||
} | ||
} |
This file contains 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