# |
May 7th 2021, 23:06 |
thomas078 |
``` public function getAuthenticationService(ServerRequestInterface $request, ResponseInterface $response) { // Instantiate the service $service = new AuthenticationService(); $service->setConfig([ 'unauthenticatedRedirect' => '/users/login', 'queryParam' => 'redirect', ]); // Load identifiers $service->loadIdentifier('Authentication.Password', [ |
# |
May 7th 2021, 23:03 |
ndm |
Don't let the trace fool you, you wouldn't see an entry for the middleware in there, as the exception is being rethrown. Add a debug statement or a breakpoint in the middleware to be sure. |
# |
May 7th 2021, 22:56 |
slackebot |
/home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Http/Server.php(97): Cake\Http\Runner->run() #20 /home/tomppa/www/gtms/webroot/index.php(40): Cake\Http\Server->run() #21 {main} Request URL: /users/index``` |
# |
May 7th 2021, 22:56 |
slackebot |
/home/tomppa/www/gtms/vendor/cakephp/authentication/src/Middleware/AuthenticationMiddleware.php(116): Cake\Http\Runner->__invoke() #17 /home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Http/Runner.php(65): Authentication\Middleware\AuthenticationMiddleware->__invoke() #18 /home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Http/Runner.php(51): Cake\Http\Runner->__invoke() #19 |
# |
May 7th 2021, 22:56 |
slackebot |
/home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\AssetMiddleware->__invoke() #14 /home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Error/Middleware/ErrorHandlerMiddleware.php(96): Cake\Http\Runner->__invoke() #15 /home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Error\Middleware\ErrorHandlerMiddleware->__invoke() #16 |
# |
May 7th 2021, 22:56 |
slackebot |
/home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Routing/Middleware/RoutingMiddleware.php(164): Cake\Http\Runner->__invoke() #11 /home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\RoutingMiddleware->__invoke() #12 /home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Routing/Middleware/AssetMiddleware.php(88): Cake\Http\Runner->__invoke() #13 |
# |
May 7th 2021, 22:56 |
slackebot |
/home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Http\BaseApplication->__invoke() #8 /home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Http/Middleware/CsrfProtectionMiddleware.php(124): Cake\Http\Runner->__invoke() #9 /home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Http\Middleware\CsrfProtectionMiddleware->__invoke() #10 |
# |
May 7th 2021, 22:56 |
slackebot |
/home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Http/ActionDispatcher.php(115): Cake\Controller\Controller->startupProcess() #5 /home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Http/ActionDispatcher.php(94): Cake\Http\ActionDispatcher->_invoke() #6 /home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Http/BaseApplication.php(234): Cake\Http\ActionDispatcher->dispatch() #7 |
# |
May 7th 2021, 22:56 |
slackebot |
/home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Event/EventManager.php(329): Cake\Event\EventManager->_callListener() #2 /home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Event/EventDispatcherTrait.php(113): Cake\Event\EventManager->dispatch() #3 /home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Controller/Controller.php(680): Cake\Controller\Controller->dispatchEvent() #4 |
# |
May 7th 2021, 22:56 |
thomas078 |
``` Error: [Authentication\Authenticator\UnauthenticatedException] No identity found. You can skip this check by configuring `requireIdentity` to be `false`. (/home/tomppa/www/gtms/vendor/cakephp/authentication/src/Controller/Component/AuthenticationComponent.php:153) #0 /home/tomppa/www/gtms/vendor/cakephp/cakephp/src/Event/EventManager.php(352): Authentication\Controller\Component\AuthenticationComponent->startup() #1 |
# |
May 7th 2021, 22:56 |
thomas078 |
does not land there. |
# |
May 7th 2021, 22:52 |
ndm |
For your redirect problem, you can debug if you land here, and if you get a valid redirect url: https://github.com/cakephp/authentication/blob/1.x/src/Middleware/AuthenticationMiddleware.php#L129-L137 |
# |
May 7th 2021, 22:50 |
ndm |
1.x is for CakePHP 3.x, and 2.x is for CakePHP 4.x, for both authentication and authorization |
# |
May 7th 2021, 22:48 |
thomas078 |
Also found something strange. Method 'App\Application::getAuthorizationService()' is not compatible with method 'Authorization\AuthorizationServiceProviderInterface::getAuthorizationService()' Trying to implement this in cake3.9. had to install composer require "cakephp/authorization:^1.0" instead of 2.0. Maybe this is not compatible with authentication 1.0? |
# |
May 7th 2021, 22:46 |
thomas078 |
strange as authentication middleware works |
# |
May 7th 2021, 22:45 |
ndm |
Maybe the authentication middleware is misplaced and something else handles the exception. |
# |
May 7th 2021, 22:42 |
thomas078 |
Application.php |
# |
May 7th 2021, 22:39 |
ndm |
maybe you're setting this in the wrong place |
# |
May 7th 2021, 22:30 |
thomas078 |
i set $service->setConfig([ 'unauthenticatedRedirect' => '/users/login', 'queryParam' => 'redirect', ]); but still i get *Error:* No identity found. You can skip this check by configuring `requireIdentity` to be `false`. but no redirect? |
# |
May 7th 2021, 22:28 |
thomas078 |
then i will really see the whole scope to see how much work to migrate from cake 3 to 4 |
# |
May 7th 2021, 22:27 |
thomas078 |
sure. Will test that as well |
# |
May 7th 2021, 22:21 |
ndm |
correct, authorization checks are done in policies now |
# |
May 7th 2021, 22:20 |
thomas078 |
and that old inAuthorized is not called nomore |
# |
May 7th 2021, 22:20 |
thomas078 |
I guess this is now with Authorization plugin |
# |
May 7th 2021, 22:19 |
thomas078 |
ok. Authentication set. Now basic Authorization. I used to do it like: public function isAuthorized($user) |
# |
May 7th 2021, 22:12 |
ndm |
yes |
# |
May 7th 2021, 22:12 |
thomas078 |
So, basically with that i can manually set it |
# |
May 7th 2021, 22:11 |
thomas078 |
ok. Got it. I was confused as Authentication already worked :) |
# |
May 7th 2021, 22:10 |
ndm |
That method _can_ be used to manually authenticate an identity, or to update a persisted identity (for example in the session). You don't _have_ to use it for authentication to work. |
# |
May 7th 2021, 22:07 |
thomas078 |
This is confusing. Maybe after identifying user i have to setIdentity as well? ```$user = $this->Users->find()->where(['Users.id' => $this->Authentication->getIdentityData('id')])->first();` $this->Authentication->setIdentity($user);``` ? |
# |
May 7th 2021, 22:01 |
thomas078 |
what does it even do as i can anyway call logged in users with $this->Authentication->getIdentity() |
# |
May 7th 2021, 22:01 |
thomas078 |
Second question. In Auth component it was like $this->Auth->setUser($user);. Do i need to call ```// Persist the user into configured authenticators. $this->Authentication->setIdentity($user);``` |
# |
May 7th 2021, 22:00 |
thomas078 |
? |
# |
May 7th 2021, 22:00 |
thomas078 |
for e.g i can call like debug($this->Authentication->getIdentityData('role')); and i will get my role, is this the correct way to do it |
# |
May 7th 2021, 21:59 |
thomas078 |
debug($this->Authentication->getIdentity()); Getting the identify object will all correct. Littlebit confused what is the correct way to get actual information. Identifiers? |
# |
May 7th 2021, 21:04 |
tyler.adam.lazenby |
its for a CI |
# |
May 7th 2021, 21:04 |
tyler.adam.lazenby |
Does anybody have any docker files they would be willing to share for cakephp 4.x and php8.0 |
# |
May 7th 2021, 20:45 |
thomas078 |
will start to play with that now |
# |
May 7th 2021, 20:45 |
thomas078 |
cool. Thanks |
# |
May 7th 2021, 20:43 |
slackebot |
] ); }``` |
# |
May 7th 2021, 20:43 |
kevin.pfeifer |
if you want to have specific actions without authentication, then yes, they should be placed in the beforeFilter in the controller like ``` public function beforeFilter( \Cake\Event\EventInterface $event ) { parent::beforeFilter( $event ); // Configure the login action to not require authentication, preventing // the infinite redirect loop issue $this->Authentication->addUnauthenticatedActions( [ 'login' |