File tree Expand file tree Collapse file tree 3 files changed +32
-3
lines changed
Expand file tree Collapse file tree 3 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -85,12 +85,12 @@ define the ``AuthenticationService`` it wants to use. Add the following method t
8585
8686 // Define where users should be redirected to when they are not authenticated
8787 $service->setConfig([
88- 'unauthenticatedRedirect' => Router::url( [
88+ 'unauthenticatedRedirect' => [
8989 'prefix' => false,
90- 'plugin' => null ,
90+ 'plugin' => false ,
9191 'controller' => 'Users',
9292 'action' => 'login',
93- ]) ,
93+ ],
9494 'queryParam' => 'redirect',
9595 ]);
9696
Original file line number Diff line number Diff line change 2626use Authentication \Identifier \IdentifierCollection ;
2727use Authentication \Identifier \IdentifierInterface ;
2828use Cake \Core \InstanceConfigTrait ;
29+ use Cake \Routing \Router ;
2930use InvalidArgumentException ;
3031use Psr \Http \Message \ResponseInterface ;
3132use Psr \Http \Message \ServerRequestInterface ;
@@ -372,6 +373,9 @@ public function getUnauthenticatedRedirectUrl(ServerRequestInterface $request):
372373 if ($ target === null ) {
373374 return null ;
374375 }
376+ if (is_array ($ target ) && class_exists (Router::class)) {
377+ $ target = Router::url ($ target );
378+ }
375379 if ($ param === null ) {
376380 return $ target ;
377381 }
Original file line number Diff line number Diff line change 3232use Cake \Http \ServerRequest ;
3333use Cake \Http \ServerRequestFactory ;
3434use Cake \I18n \DateTime ;
35+ use Cake \Routing \Router ;
3536use InvalidArgumentException ;
3637use Psr \Http \Message \RequestInterface ;
3738use Psr \Http \Message \ResponseInterface ;
@@ -818,6 +819,30 @@ public function testGetUnauthenticatedRedirectUrl()
818819 );
819820 }
820821
822+ public function testGetUnauthenticatedRedirectUrlAsArray ()
823+ {
824+ Router::fullBaseUrl ('http://localhost ' );
825+
826+ $ builder = Router::createRouteBuilder ('/ ' );
827+ $ builder ->connect (
828+ '/login ' ,
829+ ['controller ' => 'Users ' , 'action ' => 'login ' ],
830+ ['_name ' => 'login ' ],
831+ );
832+
833+ $ service = new AuthenticationService ();
834+ $ request = ServerRequestFactory::fromGlobals (
835+ ['REQUEST_URI ' => '/secrets ' ],
836+ );
837+ $ service ->setConfig ('unauthenticatedRedirect ' , [
838+ 'prefix ' => false ,
839+ 'plugin ' => false ,
840+ 'controller ' => 'Users ' ,
841+ 'action ' => 'login ' ,
842+ ]);
843+ $ this ->assertSame ('/login ' , $ service ->getUnauthenticatedRedirectUrl ($ request ));
844+ }
845+
821846 public function testGetUnauthenticatedRedirectUrlWithBasePath ()
822847 {
823848 $ request = ServerRequestFactory::fromGlobals (
You can’t perform that action at this time.
0 commit comments