From 374d84dfeba4bf8fe96e69ab6507e505b611730f Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Tue, 17 Feb 2026 14:07:09 +0100 Subject: [PATCH] feat: add consent page post authorize --- src/Controller/SecurityController.php | 12 +++++++++- .../LeaugeOAuth2AuthorizationListener.php | 11 +++++----- templates/security/consent.html.twig | 22 +++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 templates/security/consent.html.twig diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index 63b6e8c..c0a4608 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -2,6 +2,7 @@ namespace App\Controller; +use App\EventListener\LeaugeOAuth2AuthorizationListener; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -34,6 +35,15 @@ class SecurityController extends AbstractController #[Route(path: '/consent', name: 'app_consent')] public function consent(Request $request): Response { - dd($request); + if ($request->getMethod() === Request::METHOD_POST) { + $request->getSession()->set( + LeaugeOAuth2AuthorizationListener::AUTHORIZATION_RESULT, + $request->get('_consent') + ); + + return $this->redirectToRoute('oauth2_authorize', $request->query->all()); + } + + return $this->render('security/consent.html.twig'); } } diff --git a/src/EventListener/LeaugeOAuth2AuthorizationListener.php b/src/EventListener/LeaugeOAuth2AuthorizationListener.php index 419f80e..4912bc0 100644 --- a/src/EventListener/LeaugeOAuth2AuthorizationListener.php +++ b/src/EventListener/LeaugeOAuth2AuthorizationListener.php @@ -22,15 +22,16 @@ final class LeaugeOAuth2AuthorizationListener public function onAuthorizationRequestResolve(AuthorizationRequestResolveEvent $event): void { $request = $this->requestStack->getCurrentRequest(); - $authorization = $request->getSession()->get(self::AUTHORIZATION_RESULT, false); - if (!$authorization) { - $event->setResponse(new RedirectResponse($this->urlGenerator->generate('app_consent'))); + if ($request->getSession()->has(self::AUTHORIZATION_RESULT)) { + $event->resolveAuthorization($request->getSession()->get(self::AUTHORIZATION_RESULT)); + $request->getSession()->remove(self::AUTHORIZATION_RESULT); return; } - $event->resolveAuthorization($authorization); - $request->getSession()->remove(self::AUTHORIZATION_RESULT); + $event->setResponse(new RedirectResponse( + $this->urlGenerator->generate('app_consent', $request->query->all()) + )); } } diff --git a/templates/security/consent.html.twig b/templates/security/consent.html.twig new file mode 100644 index 0000000..8ae74fd --- /dev/null +++ b/templates/security/consent.html.twig @@ -0,0 +1,22 @@ +{% extends 'base.html.twig' %} + +{% block title %}Log in!{% endblock %} + +{% block body %} +
+ {% if app.user %} +
+ You are logged in as {{ app.user.userIdentifier }}, Logout +
+ {% endif %} + +
+ + +
+ + +
+{% endblock %}