SSO #1
|
|
@ -5,10 +5,8 @@ namespace App\Controller;
|
||||||
use App\Service\AccessTokenService;
|
use App\Service\AccessTokenService;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Psr\Log\LogLevel;
|
use Psr\Log\LogLevel;
|
||||||
use SessionHandlerInterface;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
use Symfony\Bundle\SecurityBundle\Security;
|
use Symfony\Bundle\SecurityBundle\Security;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
@ -45,37 +43,20 @@ class SecurityController extends AbstractController
|
||||||
#[Route(path: '/sso_logout', name: 'sso_logout')]
|
#[Route(path: '/sso_logout', name: 'sso_logout')]
|
||||||
public function ssoLogout(RequestStack $stack, LoggerInterface $logger, AccessTokenService $accessTokenService, Security $security): Response
|
public function ssoLogout(RequestStack $stack, LoggerInterface $logger, AccessTokenService $accessTokenService, Security $security): Response
|
||||||
{
|
{
|
||||||
|
// Invalidate the session and revoke tokens
|
||||||
try{
|
try{
|
||||||
if( $stack->getSession()->invalidate()){
|
if( $stack->getSession()->invalidate()){
|
||||||
$accessTokenService->revokeTokens($security->getUser()->getUserIdentifier());
|
$accessTokenService->revokeTokens($security->getUser()->getUserIdentifier());
|
||||||
$security->logout(false);
|
$security->logout(false);
|
||||||
$logger->info("Session invalidated successfully");
|
$logger->info("Logout successfully");
|
||||||
} else {
|
// Redirect back to the client (or to a “you are logged out” page)
|
||||||
$logger->info("Session already invalidated or not started");
|
return $this->redirect('/');
|
||||||
}
|
}
|
||||||
}catch (\Exception $e){
|
}catch (\Exception $e){
|
||||||
$logger->log(LogLevel::ERROR, 'Error invalidating session: ' . $e->getMessage());
|
$logger->log(LogLevel::ERROR, 'Error invalidating session: ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
// try{
|
// If something goes wrong, redirect to the index page
|
||||||
// $security->logout(false);
|
return $this->redirectToRoute('app_index');
|
||||||
// }catch (\Exception $e){
|
|
||||||
// $logger->log(LogLevel::ERROR, 'Error during logout: ' . $e->getMessage());
|
|
||||||
// }
|
|
||||||
// $security->logout(false);
|
|
||||||
// try{
|
|
||||||
// $logger->info("Destruction de la session");
|
|
||||||
// $sessionHandler->destroy("089gn04mts0iiiskfji8sjqr15");
|
|
||||||
// }catch(\Exception $e){
|
|
||||||
// // Log the error if needed
|
|
||||||
// $logger->error("Erreur lors de la destruction de la session". $e->getMessage());
|
|
||||||
// }
|
|
||||||
$logger->info("Logout successfully");
|
|
||||||
// Redirect back to the client (or to a “you are logged out” page)
|
|
||||||
// $redirect = $request->query->get('redirect_uri', '/');
|
|
||||||
return $this->redirect('/');
|
|
||||||
// return new JsonResponse(["SUCCESS" => "Tokens revoked successfully"], Response::HTTP_OK);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Route(path: '/consent', name: 'app_consent')]
|
#[Route(path: '/consent', name: 'app_consent')]
|
||||||
|
|
@ -97,5 +78,4 @@ class SecurityController extends AbstractController
|
||||||
return $this->render('security/consent.html.twig');
|
return $this->render('security/consent.html.twig');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue