From b4f0890a7d2c682015face291f003f6ed9375a49 Mon Sep 17 00:00:00 2001 From: mscherer Date: Tue, 18 Mar 2025 01:43:55 +0100 Subject: [PATCH 1/2] Controller Usage --- docs/en/request-authorization-middleware.rst | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/en/request-authorization-middleware.rst b/docs/en/request-authorization-middleware.rst index 756d3fe..f8e0c7a 100644 --- a/docs/en/request-authorization-middleware.rst +++ b/docs/en/request-authorization-middleware.rst @@ -78,3 +78,28 @@ AuthorizationMiddleware:: $middlewareQueue->add(new AuthorizationMiddleware($this)); $middlewareQueue->add(new RequestAuthorizationMiddleware()); } + +Controller Usage +================ + +When having fallback routing activated, all asset based 404s as well as not existing controllers would also +trigger the RequestAuthorizationMiddleware. +In this case, it is possible to use this middleware only for your (App)controller:: + + public function initialize(): void + { + parent::initialize(); + + $this->middleware(function ($request, $handler): ResponseInterface { + $config = [ + 'unauthorizedHandler' => [ + ... + ], + ]; + $middleware = new RequestAuthorizationMiddleware($config); + + return $middleware->process($request, $handler); + }); + } + +Also note, that in this case you will e.g. need ``'DebugKit.ignoreAuthorization'`` set to ``true``. From 977bfd1cb93822c8082ed69ef281c9591fac0e7a Mon Sep 17 00:00:00 2001 From: Mark Scherer Date: Sun, 20 Apr 2025 00:05:27 +0200 Subject: [PATCH 2/2] Update request-authorization-middleware.rst --- docs/en/request-authorization-middleware.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/request-authorization-middleware.rst b/docs/en/request-authorization-middleware.rst index f8e0c7a..792db0b 100644 --- a/docs/en/request-authorization-middleware.rst +++ b/docs/en/request-authorization-middleware.rst @@ -86,6 +86,7 @@ When having fallback routing activated, all asset based 404s as well as not exis trigger the RequestAuthorizationMiddleware. In this case, it is possible to use this middleware only for your (App)controller:: + // src/Controller/AppController.php public function initialize(): void { parent::initialize();