From 27706d63f4933813162b1c55446f9236c0afd007 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sun, 13 Mar 2022 22:27:59 +0000 Subject: [PATCH] [PLUGIN][OAuth] Fix login for OAuth --- config/packages/security.yaml | 4 +--- plugins/OAuth2/Controller/Authorize.php | 9 +++++---- src/Util/Exception/NoLoggedInUser.php | 2 +- templates/security/login.html.twig | 4 ++-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/config/packages/security.yaml b/config/packages/security.yaml index e9a4dbb7a9..22c197a81b 100644 --- a/config/packages/security.yaml +++ b/config/packages/security.yaml @@ -20,15 +20,13 @@ security: dev: pattern: ^/(_(profiler|wdt)|css|images|js)/ security: false - oauth: - pattern: ^/oauth - security: false main: lazy: true provider: local_user form_login: login_path: security_login check_path: security_login + default_target_path: root logout: path: security_logout # where to redirect after logout diff --git a/plugins/OAuth2/Controller/Authorize.php b/plugins/OAuth2/Controller/Authorize.php index 6d9e10030a..979255fde8 100644 --- a/plugins/OAuth2/Controller/Authorize.php +++ b/plugins/OAuth2/Controller/Authorize.php @@ -34,7 +34,7 @@ declare(strict_types = 1); namespace Plugin\OAuth2\Controller; use App\Core\Controller; -use App\Entity\LocalUser; +use App\Util\Common; use App\Util\Exception\NotFoundException; use League\OAuth2\Server\Entities\UserEntityInterface; use League\OAuth2\Server\Exception\OAuthServerException; @@ -56,7 +56,7 @@ class Authorize extends Controller parent::__construct($stack); } - public function __invoke(Request $request) + public function handle(Request $request) { // @var \League\OAuth2\Server\AuthorizationServer $server $server = OAuth2::$authorization_server; @@ -71,10 +71,11 @@ class Authorize extends Controller $psrRequest = $psrHttpFactory->createRequest($request); $authRequest = $server->validateAuthorizationRequest($psrRequest); - // TODO + $user = Common::ensureLoggedIn($request); + // Once the user has logged in set the user on the AuthorizationRequest $authRequest->setUser( - new class(LocalUser::getByNickname('foo')->getId()) implements UserEntityInterface { + new class($user->getId()) implements UserEntityInterface { public function __construct(private int $id) { } diff --git a/src/Util/Exception/NoLoggedInUser.php b/src/Util/Exception/NoLoggedInUser.php index 95d0022c63..62c639abdb 100644 --- a/src/Util/Exception/NoLoggedInUser.php +++ b/src/Util/Exception/NoLoggedInUser.php @@ -37,6 +37,6 @@ class NoLoggedInUser extends RedirectException { public function __construct(Request $request) { - parent::__construct('security_login', ['next' => $request->getRequestUri()]); + parent::__construct('security_login', ['_target_path' => $request->getRequestUri()]); } } diff --git a/templates/security/login.html.twig b/templates/security/login.html.twig index a41ac27414..9bc4d61017 100644 --- a/templates/security/login.html.twig +++ b/templates/security/login.html.twig @@ -41,8 +41,8 @@ - {% if app.request.query.has('next') %} - + {% if app.request.query.has('next') or app.request.query.has('_next') or app.request.query.has('_target_path') %} + {% endif %}