Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions docs/en/request-authorization-middleware.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,29 @@ 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::

// src/Controller/AppController.php
public function initialize(): void
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we include a comment indicating which file this should go in?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its in the sentence before: "for your (App)controller"
But we can make it more clear, sure.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@markstory Done.

{
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``.
Loading