# |
Jul 23rd 2021, 13:26 |
paolo.bragagni |
and not to https://cakephp.local/myapp/users/login |
# |
Jul 23rd 2021, 13:26 |
paolo.bragagni |
https://cakephp.local/users/login |
# |
Jul 23rd 2021, 13:26 |
paolo.bragagni |
it redirects to |
# |
Jul 23rd 2021, 13:26 |
kevin.pfeifer |
and the ```$request->getFlash()->error('You are not authorized to access that location');``` needs to be added anywhere in the handle function before the reutnr |
# |
Jul 23rd 2021, 13:24 |
kevin.pfeifer |
and adjust the namespace to `namespace App\Middleware\UnauthorizedHandler;` |
# |
Jul 23rd 2021, 13:24 |
kevin.pfeifer |
if you copied the whole RedirectHandler then you will have to add at least ```use Authorization\Middleware\UnauthorizedHandler\HandlerInterface;``` at the top since the interface can’t be autoloaded |
# |
Jul 23rd 2021, 13:22 |
paolo.bragagni |
steps ahead |
# |
Jul 23rd 2021, 13:20 |
kevin.pfeifer |
ok and ```use Authorization\Exception\ForbiddenException; ``` at the top |
# |
Jul 23rd 2021, 13:20 |
paolo.bragagni |
$middlewareQueue->add(new AuthorizationMiddleware($this, [ 'requireAuthorizationCheck' => false, 'unauthorizedHandler' => [ 'className' => 'Regtosc', 'url' => '/users/login', 'queryParam' => 'redirectUrl', 'exceptions' => [ ForbiddenException::class, MissingIdentityException::class, OtherException::class, ], ], ])); |
# |
Jul 23rd 2021, 13:19 |
kevin.pfeifer |
do you have the `ForbiddenException::class` in your exceptions array |
# |
Jul 23rd 2021, 13:18 |
kevin.pfeifer |
check your middleware |
# |
Jul 23rd 2021, 13:18 |
paolo.bragagni |
*Identity is not authorized to perform `add` on `App\Model\Entity\Libro`.* |
# |
Jul 23rd 2021, 13:18 |
paolo.bragagni |
but it doesnt redirect |
# |
Jul 23rd 2021, 13:17 |
kevin.pfeifer |
ok sure |
# |
Jul 23rd 2021, 13:17 |
paolo.bragagni |
no. now I've copied all redirect handler to my handler |
# |
Jul 23rd 2021, 13:17 |
kevin.pfeifer |
``` // Add authorization **after** authentication ->add(new AuthorizationMiddleware($this, [ 'unauthorizedHandler' => [ 'className' => 'CustomRedirect', 'url' => '/users/login', 'queryParam' => 'redirectUrl', 'exceptions' => [ MissingIdentityException::class, ForbiddenException::class ], ], ]))``` |
# |
Jul 23rd 2021, 13:15 |
kevin.pfeifer |
so its not working for you? |
# |
Jul 23rd 2021, 13:14 |
kevin.pfeifer |
basically what is done here https://github.com/cakephp/authorization/blob/master/src/Middleware/UnauthorizedHandler/RedirectHandler.php#L61 |
# |
Jul 23rd 2021, 13:14 |
paolo.bragagni |
a little bit too much for me :S |
# |
Jul 23rd 2021, 13:13 |
kevin.pfeifer |
and you have to tell the handler which exceptions it should “listen” to |
# |
Jul 23rd 2021, 13:13 |
kevin.pfeifer |
the handler only redirects certain exceptions |
# |
Jul 23rd 2021, 13:10 |
kevin.pfeifer |
and `use Authorization\Exception\ForbiddenException;` at the top |
# |
Jul 23rd 2021, 13:10 |
kevin.pfeifer |
you need to add `ForbiddenException::class` to the `exception` array |
# |
Jul 23rd 2021, 13:09 |
kevin.pfeifer |
as said, thats a different exception |
# |
Jul 23rd 2021, 13:08 |
paolo.bragagni |
*Identity is not authorized to perform `add` on `App\Model\Entity\Libro`* |
# |
Jul 23rd 2021, 13:05 |
kevin.pfeifer |
depending on the thrown execption could be that you need to adjust the expections array in the config |
# |
Jul 23rd 2021, 13:05 |
kevin.pfeifer |
works for me now :thinking_face: |
# |
Jul 23rd 2021, 13:04 |
paolo.bragagni |
mmm |
# |
Jul 23rd 2021, 13:04 |
kevin.pfeifer |
try to just return false to test it |
# |
Jul 23rd 2021, 13:04 |
kevin.pfeifer |
thats a problem inside your policy |
# |
Jul 23rd 2021, 13:00 |
paolo.bragagni |
*Pre-authorization check must return `Authorization\Policy\ResultInterface`, `bool` or `null`.* |
# |
Jul 23rd 2021, 12:56 |
kevin.pfeifer |
well i basically copied my values from the use statement but i forgot that you need to add the \ if youre not using the class via the use |
# |
Jul 23rd 2021, 12:54 |
paolo.bragagni |
before Authorization |
# |
Jul 23rd 2021, 12:52 |
kevin.pfeifer |
could be that i forgot the \ at the front of App ,:) |
# |
Jul 23rd 2021, 12:51 |
paolo.bragagni |
*Interface 'App\Middleware\UnauthorizedHandler\Authorization\Middleware\UnauthorizedHandler\HandlerInterface' not found* |
# |
Jul 23rd 2021, 12:49 |
kevin.pfeifer |
basically i forgot the extend of the already present RedirectHandler |
# |
Jul 23rd 2021, 12:49 |
kevin.pfeifer |
check again, should be more clear now |
# |
Jul 23rd 2021, 12:44 |
paolo.bragagni |
fighting with namespaces |
# |
Jul 23rd 2021, 12:39 |
kevin.pfeifer |
i mixed 2 things together, let me fix that |
# |
Jul 23rd 2021, 12:39 |
kevin.pfeifer |
ah sorry, i forgot something |
# |
Jul 23rd 2021, 12:37 |
paolo.bragagni |
wait |