# |
May 19th 2021, 09:22 |
kevin.pfeifer |
as stated in https://book.cakephp.org/authorization/2/en/middleware.html#handling-unauthorized-requests |
# |
May 19th 2021, 09:22 |
slackebot |
],``` |
# |
May 19th 2021, 09:22 |
kevin.pfeifer |
I just checked your screenshot again and it seems you misplaced the `exceptions` array. It should be inside the `unatuhorizedHandler` array like that ``` 'unauthorizedHandler' => [ 'className' => 'Authorization.Redirect', 'url' => '/users/login', 'queryParam' => 'redirectUrl', 'exceptions' => [ MissingIdentityException::class, OtherException::class, ], |
# |
May 19th 2021, 09:13 |
neon1024 |
Dirty, but it works |
# |
May 19th 2021, 08:59 |
neon1024 |
Well I have a meeting. Thanks for the help though, really appreciated it. This is the start of Day 2 trying to get this Authorization plugin working ,:) |
# |
May 19th 2021, 08:58 |
neon1024 |
I tried catching the instantiation of the service also, but as it’s middleware, you can’t |
# |
May 19th 2021, 08:57 |
neon1024 |
Otherwise I guess we can’t use the Authorization plugin as it basically doesn’t work |
# |
May 19th 2021, 08:57 |
neon1024 |
That’s why I thought I’d just extend the class and I can catch that exception myself |
# |
May 19th 2021, 08:56 |
neon1024 |
Ah a short class name is no help `use Authorization\Exception\ForbiddenException;` |
# |
May 19th 2021, 08:56 |
neon1024 |
Looks the same |
# |
May 19th 2021, 08:56 |
slackebot |
<neon1024> |
# |
May 19th 2021, 08:55 |
kevin.pfeifer |
is it probably a different exception then the one i wrote above? |
# |
May 19th 2021, 08:53 |
neon1024 |
Well, I’ll see once my Docker containers are done crashing. That `docker.hyperkit` ruins my Macbook |
# |
May 19th 2021, 08:52 |
neon1024 |
Odd, I am still just getting an exception |
# |
May 19th 2021, 08:50 |
neon1024 |
I guess this is the hook https://github.com/cakephp/authorization/blob/2.1.0/src/Middleware/AuthorizationMiddleware.php#L134-L140 |
# |
May 19th 2021, 08:50 |
neon1024 |
Making work for conference speakers :P |
# |
May 19th 2021, 08:49 |
kevin.pfeifer |
yea, we definitely need to adjust the doc |
# |
May 19th 2021, 08:49 |
neon1024 |
Magic methods and now secret configuration! |
# |
May 19th 2021, 08:49 |
neon1024 |
Bit annoying that it’s not in the docblock :( |
# |
May 19th 2021, 08:49 |
kevin.pfeifer |
which for authorization is `\Authorization\Exception\ForbiddenException` |
# |
May 19th 2021, 08:48 |
kevin.pfeifer |
yea and in there you can extend the exceptions array which should be caught and then redirected |
# |
May 19th 2021, 08:48 |
slackebot |
<neon1024> |
# |
May 19th 2021, 08:48 |
neon1024 |
Yes, same! |
# |
May 19th 2021, 08:47 |
kevin.pfeifer |
we had a similar issue on monday :) |
# |
May 19th 2021, 08:47 |
slackebot |
<kevin.pfeifer> |
# |
May 19th 2021, 08:47 |
neon1024 |
Ahok, fair enough, Easily done! |
# |
May 19th 2021, 08:47 |
kevin.pfeifer |
its an options available on the authorization middleware |
# |
May 19th 2021, 08:46 |
kevin.pfeifer |
ah sorry, i mixed up authentication and authorization again |
# |
May 19th 2021, 08:45 |
neon1024 |
https://github.com/cakephp/authentication/blob/2.6.1/src/Middleware/AuthenticationMiddleware.php#L49-L50 |
# |
May 19th 2021, 08:45 |
neon1024 |
I only see a redirect which I have included |
# |
May 19th 2021, 08:44 |
neon1024 |
I don’t see that option, let me double check |
# |
May 19th 2021, 08:43 |
kevin.pfeifer |
you need to add the `\Authorization\Exception\ForbiddenException` to the `unauthorizedHandler` option set in the authenticationmiddleware |
# |
May 19th 2021, 08:43 |
neon1024 |
Feels like a dead-end |
# |
May 19th 2021, 08:43 |
neon1024 |
Even then, I’m unsure how you’d redirect a user from a middleware |
# |
May 19th 2021, 08:41 |
neon1024 |
All I can think is to extend the class and catch the exception myself in the custom class |
# |
May 19th 2021, 08:40 |
neon1024 |
Unless I’m mistaken there seems to be a bug in the Authorization plugin’s RequestAuthorizationMiddleware. If you load it, and hit a url without an indentity, you get an Exception. However, it’s not possible to catch that exception and redirect the user to create an indentity (login) |
# |
May 19th 2021, 01:15 |
ndm |
sometimes... maybe... thanks :upside_down_face: |
# |
May 18th 2021, 20:52 |
caseyw |
You are one fine human being. |
# |
May 18th 2021, 20:21 |
slackebot |
$this->mockService(FooMiddleware::class, function () { $fooMiddlewareMock = $this ->getMockBuilder(FooMiddleware::class) ->onlyMethods(['process']) ->getMock(); // ... return $fooMiddlewareMock; }); $this->get('/foo/bar'); // ... }``` |
# |
May 18th 2021, 20:21 |
slackebot |
$this->getContainer()->get(FooMiddleware::class); $routes->registerMiddleware('foo', $fooMiddleware); $routes->connect('/foo/bar', function (RouteBuilder $routes) { $routes->applyMiddleware('foo'); }); }``` ```public function testFooBar() { // this method keeps a list of mocks/objects, which is being used // to modify the container when the app dispatches the event |
# |
May 18th 2021, 20:21 |
ndm |
No problem... to close off, a quick and dirty example of what it probably somewhat would look like in 4.2, just to give you an idea: ```// event is being dispatched after this method has been invoked public function services(ContainerInterface $container): void { $container->add(FooMiddleware::class); } public function routes(RouteBuilder $routes): void { parent::routes($routes); $fooMiddleware = |