File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -383,14 +383,20 @@ public function buildIdentity(ArrayAccess|array $identityData): IdentityInterfac
383383 */
384384 public function getUnauthenticatedRedirectUrl (ServerRequestInterface $ request ): ?string
385385 {
386- $ param = $ this ->getConfig ('queryParam ' );
387386 $ target = $ this ->getConfig ('unauthenticatedRedirect ' );
388387 if ($ target === null ) {
389388 return null ;
390389 }
390+
391391 if (is_array ($ target ) && class_exists (Router::class)) {
392392 $ target = Router::url ($ target );
393393 }
394+
395+ if ($ request ->getMethod () !== 'GET ' ) {
396+ return $ target ;
397+ }
398+
399+ $ param = $ this ->getConfig ('queryParam ' );
394400 if ($ param === null ) {
395401 return $ target ;
396402 }
Original file line number Diff line number Diff line change @@ -847,6 +847,22 @@ public function testGetUnauthenticatedRedirectUrl()
847847 );
848848 }
849849
850+ public function testGetUnauthenticatedRedirectUrlForPost ()
851+ {
852+ $ service = new AuthenticationService ();
853+ $ service ->setConfig ('unauthenticatedRedirect ' , '/users/login ' );
854+ $ service ->setConfig ('queryParam ' , 'redirect ' );
855+
856+ $ request = ServerRequestFactory::fromGlobals (
857+ ['REQUEST_URI ' => '/secrets ' , 'REQUEST_METHOD ' => 'POST ' ],
858+ );
859+ $ this ->assertSame (
860+ '/users/login ' ,
861+ $ service ->getUnauthenticatedRedirectUrl ($ request ),
862+ 'Redirect query param should be only set for GET requests ' ,
863+ );
864+ }
865+
850866 public function testGetUnauthenticatedRedirectUrlAsArray ()
851867 {
852868 Router::fullBaseUrl ('http://localhost ' );
You can’t perform that action at this time.
0 commit comments