cakephp / authorization

PSR7 Middleware for authorization
MIT License
76 stars 47 forks source link

Redirect is not working for me #141

Closed enviniom closed 4 years ago

enviniom commented 4 years ago

Hi, I can't make a redirect for unathorized actions, and i made configuration like say in docs:

'unauthorizedHandler' => [
                    'className' => 'Authorization.Redirect',
                    'url' => '/principal/noauthorized',
                    'queryParam' => 'redirectUrl',
                    'exceptions' => [
                        MissingIdentityException::class,
                        OtherException::class,
                    ],
                ], 

But, still shows the error page with "Identity is not authorized to perform (...)" and I can't redirect to /principal/noauthorized

ndm2 commented 4 years ago

You'd have to add \Authorization\Exception\ForbiddenException to the list of handled exceptions to catch those errors, that is what is being thrown by the request handler middleware and by the authorization component (unless you're doing manual can* checks).

https://stackoverflow.com/questions/59976845/cakephp-4-authentication-plugin-requestauthorizationmiddleware-redirect-url-miss/59977415#59977415

enviniom commented 4 years ago

Thanks a lot, now it is working.