add logout subscriber and update SSO logout handling
This commit is contained in:
parent
d50a6bd238
commit
5abbd15b45
2
.env
2
.env
|
|
@ -75,3 +75,5 @@ AWS_S3_PORTAL_URL=https://s3.amazonaws.com/portal
|
||||||
###< aws/aws-sdk-php-symfony ###
|
###< aws/aws-sdk-php-symfony ###
|
||||||
APP_URL='https://example.com'
|
APP_URL='https://example.com'
|
||||||
APP_DOMAIN='example.com'
|
APP_DOMAIN='example.com'
|
||||||
|
|
||||||
|
EASYCHECK_URL='https://check.solutions-easy.com'
|
||||||
|
|
@ -13,6 +13,7 @@ parameters:
|
||||||
logos_directory: '%kernel.project_dir%/public/uploads/logos'
|
logos_directory: '%kernel.project_dir%/public/uploads/logos'
|
||||||
oauth_sso_identifier: '%env(OAUTH_SSO_IDENTIFIER)%'
|
oauth_sso_identifier: '%env(OAUTH_SSO_IDENTIFIER)%'
|
||||||
oauth_sso_identifier_login: '%env(OAUTH_SSO_IDENTIFIER_LOGIN)%'
|
oauth_sso_identifier_login: '%env(OAUTH_SSO_IDENTIFIER_LOGIN)%'
|
||||||
|
easycheck_url: '%env(EASYCHECK_URL)%'
|
||||||
|
|
||||||
services:
|
services:
|
||||||
# default configuration for services in *this* file
|
# default configuration for services in *this* file
|
||||||
|
|
@ -59,3 +60,9 @@ services:
|
||||||
|
|
||||||
# add more service definitions when explicit configuration is needed
|
# add more service definitions when explicit configuration is needed
|
||||||
# please note that last definitions always *replace* previous ones
|
# please note that last definitions always *replace* previous ones
|
||||||
|
|
||||||
|
App\EventListener\LogoutSubscriber:
|
||||||
|
arguments:
|
||||||
|
$easycheckUrl: '%env(EASYCHECK_URL)%'
|
||||||
|
tags:
|
||||||
|
- { name: kernel.event_subscriber }
|
||||||
|
|
|
||||||
|
|
@ -55,9 +55,16 @@ class SecurityController extends AbstractController
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route(path: '/sso_logout', name: 'sso_logout')]
|
#[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 {
|
try {
|
||||||
$user = $this->getUser();
|
$user = $this->getUser();
|
||||||
|
|
@ -73,7 +80,7 @@ class SecurityController extends AbstractController
|
||||||
$this->logger->log(LogLevel::ERROR, 'Error during SSO logout: ' . $e->getMessage());
|
$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');
|
return $this->redirectToRoute('app_logout');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -123,7 +123,7 @@
|
||||||
<i class="me-2">{{ ux_icon('bi:gear', {height: '20px', width: '20px'}) }}</i>
|
<i class="me-2">{{ ux_icon('bi:gear', {height: '20px', width: '20px'}) }}</i>
|
||||||
Profil
|
Profil
|
||||||
</a>
|
</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>
|
<i class="me-2">{{ ux_icon('material-symbols:logout', {height: '20px', width: '20px'}) }}</i>
|
||||||
Deconnexion
|
Deconnexion
|
||||||
</a>
|
</a>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue