authorization
authorization copied to clipboard
RequestAuthorizationMiddleware config redirect url missing
I try to use to add the RequestAuthorizationMiddleware for some controller in my application in cake 4. In the Authorization Middleware i see a code block like this:
$middlewareQueue->add(new AuthorizationMiddleware($this, [
'unauthorizedHandler' => [
'className' => 'Authorization.Redirect',
'url' => '/users/login',
'queryParam' => 'redirectUrl',
'exceptions' => [
MissingIdentityException::class,
OtherException::class,
],
],
]));
I can add a redirect url if the authorization failed. This work fine but how i can add a redirect url for the Request Authorization Middleware ?
The RequestAuthorizationMiddleware doesn't support redirect options at this time. It could be added in a future release. Would you like to help add that option?
Yeah. I would like to help to implement this feature and maybe other features in future.
Can't you just throw a Authorization\Exception\Exception which AuthorizationMiddleware will catch? You can re-use the unauthorizedHandler config for requests.
@othercorey that wouldn't work because, when throwing an exception in a RequestPolicy class (that is, a class that implements the RequestPolicyInterface interface), that exception needs to be caught in the RequestAuthorizationMiddleware, and not in the AuthorizationMiddleware.
In fact, the process method of AuthorizationMiddleware has a try/catch block, while the process method of RequestAuthorizationMiddleware doesn't.
I have opened a pull request to fix that. Please let me know.