add logout subscriber and update SSO logout handling

This commit is contained in:
mathis 2026-02-27 10:05:00 +01:00
parent d50a6bd238
commit 5abbd15b45
5 changed files with 57 additions and 5 deletions

2
.env
View File

@ -75,3 +75,5 @@ AWS_S3_PORTAL_URL=https://s3.amazonaws.com/portal
###< aws/aws-sdk-php-symfony ###
APP_URL='https://example.com'
APP_DOMAIN='example.com'
EASYCHECK_URL='https://check.solutions-easy.com'

View File

@ -13,6 +13,7 @@ parameters:
logos_directory: '%kernel.project_dir%/public/uploads/logos'
oauth_sso_identifier: '%env(OAUTH_SSO_IDENTIFIER)%'
oauth_sso_identifier_login: '%env(OAUTH_SSO_IDENTIFIER_LOGIN)%'
easycheck_url: '%env(EASYCHECK_URL)%'
services:
# default configuration for services in *this* file
@ -59,3 +60,9 @@ services:
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
App\EventListener\LogoutSubscriber:
arguments:
$easycheckUrl: '%env(EASYCHECK_URL)%'
tags:
- { name: kernel.event_subscriber }

View File

@ -55,9 +55,16 @@ class SecurityController extends AbstractController
}
#[Route(path: '/sso_logout', name: 'sso_logout')]
public function ssoLogout(AccessTokenService $accessTokenService): Response
public function ssoLogout(AccessTokenService $accessTokenService, Request $request): Response
{
$this->logger->info('SSO Logout called from EasyCheck');
$fromEasycheck = $request->query->get('from_easycheck');
if ($fromEasycheck) {
$this->logger->info('SSO Logout called from EasyCheck - completing logout');
return $this->redirectToRoute('app_logout');
}
$this->logger->info('SSO Logout initiated from Portal');
try {
$user = $this->getUser();
@ -73,7 +80,7 @@ class SecurityController extends AbstractController
$this->logger->log(LogLevel::ERROR, 'Error during SSO logout: ' . $e->getMessage());
}
$this->logger->info('Redirecting to app_logout');
$this->logger->info('Redirecting to app_logout (will trigger LogoutSubscriber)');
return $this->redirectToRoute('app_logout');
}

View File

@ -0,0 +1,36 @@
<?php
namespace App\EventListener;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Http\Event\LogoutEvent;
class LogoutSubscriber implements EventSubscriberInterface
{
public function __construct(
private readonly string $easycheckUrl,
private readonly LoggerInterface $logger
) {
}
public static function getSubscribedEvents(): array
{
return [
LogoutEvent::class => 'onLogout',
];
}
public function onLogout(LogoutEvent $event): void
{
$easycheckLogoutUrl = $this->easycheckUrl . '/logout';
$this->logger->info('LogoutSubscriber triggered - redirecting to EasyCheck logout', [
'easycheck_logout_url' => $easycheckLogoutUrl,
'user' => $event->getToken()?->getUserIdentifier()
]);
$event->setResponse(new RedirectResponse($easycheckLogoutUrl));
}
}

View File

@ -123,7 +123,7 @@
<i class="me-2">{{ ux_icon('bi:gear', {height: '20px', width: '20px'}) }}</i>
Profil
</a>
<a class="dropdown-item" style="padding-left: 8px;" href="{{ path('sso_logout') }}">
<a class="dropdown-item" style="padding-left: 8px;" href="{{ path('sso_logout') }}" data-turbo="false">
<i class="me-2">{{ ux_icon('material-symbols:logout', {height: '20px', width: '20px'}) }}</i>
Deconnexion
</a>