Allow callable for requireAuthorizationCheck config option#322
Open
dereuromark wants to merge 1 commit into3.xfrom
Open
Allow callable for requireAuthorizationCheck config option#322dereuromark wants to merge 1 commit into3.xfrom
dereuromark wants to merge 1 commit into3.xfrom
Conversation
This allows applications to conditionally skip the authorization check
based on the request. This is useful when integrating plugins that have
their own admin panels and manage authorization independently (e.g.,
queue management dashboards).
The callable receives the ServerRequestInterface and should return a
boolean - true to require authorization check (default), false to skip.
Example use case:
```php
$middlewareQueue->add(new AuthorizationMiddleware($this, [
'requireAuthorizationCheck' => function ($request) {
$path = $request->getUri()->getPath();
if (str_contains($path, '/admin/queue')) {
return false;
}
return true;
}
]));
```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for a callable in the
requireAuthorizationCheckmiddleware configuration option. Currently, this option only accepts a boolean value, but applications often need to conditionally skip authorization checks based on the request path or other request attributes.Use Case
When integrating third-party plugins that provide their own admin panels (e.g., queue management dashboards), these plugins may manage authorization independently. The host application needs a way to skip the middleware's authorization check for these specific routes without disabling it globally.
Before this PR, applications had to wrap the middleware in a custom closure:
After this PR, the same can be achieved cleanly:
Changes
AuthorizationMiddleware::process()to check ifrequireAuthorizationCheckis callable and invoke it with the requesttrue(requires authorization check)false(skips authorization check)Backwards Compatibility
This change is fully backwards compatible. The existing boolean behavior is preserved - the callable is only invoked if the config value is callable.