From 1a4ee293c8e236fd59137a6ca5aed8f75572479b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horv=C3=A1th=20P=C3=A9ter?= Date: Sun, 13 Sep 2020 00:03:29 +0200 Subject: [PATCH 1/5] upgrade to latest Dilex --- composer.json | 7 ++++--- src/JwtGuard.php | 5 +++-- test/{ => JwtGuard}/JwtTokenAuthenticatorTest.php | 0 test/JwtGuardTest.php | 8 ++------ 4 files changed, 9 insertions(+), 11 deletions(-) rename test/{ => JwtGuard}/JwtTokenAuthenticatorTest.php (100%) diff --git a/composer.json b/composer.json index b0d6c8f..c221a17 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,12 @@ { "name": "clearbooks/dilex-jwt", "description": "JWT authentication middleware for Dilex", - "type": "project", + "type": "library", "require": { "php": ">=7.2", - "clearbooks/dilex": "^2.0", - "emarref/jwt": "^1.0.3" + "clearbooks/dilex": "dev-migrate-silex-to-symfony", + "emarref/jwt": "^1.0.3", + "ext-json": "*" }, "require-dev": { diff --git a/src/JwtGuard.php b/src/JwtGuard.php index 8cb5605..a149e41 100644 --- a/src/JwtGuard.php +++ b/src/JwtGuard.php @@ -1,11 +1,12 @@ assertContains( 'error', array_keys( json_decode( $guard->execute( new Request )->getContent(), true ) ) ); - } /** @@ -67,5 +64,4 @@ public function givenInvalidRequest_AndControllerDoesNotRequireJwt_whenExecuting $this->request->attributes->set('_controller', MockNoJwtRequiredController::class ); $this->assertNull($guard->execute($this->request)); } - } From 9ef7b2b25a48a6339acbbca9ea06d555896ad0ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horv=C3=A1th=20P=C3=A9ter?= Date: Sun, 13 Sep 2020 00:51:19 +0200 Subject: [PATCH 2/5] latest dilex --- src/JwtGuard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JwtGuard.php b/src/JwtGuard.php index a149e41..9ba9362 100644 --- a/src/JwtGuard.php +++ b/src/JwtGuard.php @@ -6,7 +6,7 @@ use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; -class JwtGuard implements BeforeRequestListener +class JwtGuard implements Middleware { /** * @var RequestAuthoriser From bc09facfdbc941d9e2b92ae507cd00fd142b9c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horv=C3=A1th=20P=C3=A9ter?= Date: Sun, 13 Sep 2020 02:49:34 +0200 Subject: [PATCH 3/5] fix fetching controller class --- src/JwtGuard.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/JwtGuard.php b/src/JwtGuard.php index 9ba9362..81cb515 100644 --- a/src/JwtGuard.php +++ b/src/JwtGuard.php @@ -29,7 +29,7 @@ public function __construct( RequestAuthoriser $authoriser ) */ public function execute( Request $request ) { - $controllerClass = $request->attributes->get('_controller'); + $controllerClass = $request->attributes->get('_controller')[0]; if( !($this->isJwtRequired($controllerClass))) { return null; } From c33743e54ee0c5bfafe27a80734d0cfee72d4cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horv=C3=A1th=20P=C3=A9ter?= Date: Sun, 13 Sep 2020 22:30:22 +0200 Subject: [PATCH 4/5] controller retriever fix --- src/JwtGuard.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/JwtGuard.php b/src/JwtGuard.php index 81cb515..f730b9e 100644 --- a/src/JwtGuard.php +++ b/src/JwtGuard.php @@ -22,6 +22,16 @@ public function __construct( RequestAuthoriser $authoriser ) $this->authoriser = $authoriser; } + private function getControllerClass( Request $request ) + { + $controllerAttribute = $request->attributes->get( "_controller" ); + if ( is_array( $controllerAttribute ) ) { + return $controllerAttribute[0]; + } + + return $controllerAttribute; + } + /** * Authorise this request * @param Request $request @@ -29,7 +39,7 @@ public function __construct( RequestAuthoriser $authoriser ) */ public function execute( Request $request ) { - $controllerClass = $request->attributes->get('_controller')[0]; + $controllerClass = $this->getControllerClass( $request ); if( !($this->isJwtRequired($controllerClass))) { return null; } From 504a2046afcb1af08e40c288368104882704a1f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horv=C3=A1th=20P=C3=A9ter?= Date: Thu, 29 Oct 2020 17:53:41 +0100 Subject: [PATCH 5/5] require latest dilex --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c221a17..978511d 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "library", "require": { "php": ">=7.2", - "clearbooks/dilex": "dev-migrate-silex-to-symfony", + "clearbooks/dilex": "^3.0.0-alpha.1", "emarref/jwt": "^1.0.3", "ext-json": "*"