Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Middleware/UnauthorizedHandler/CakeRedirectHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ protected function getUrl(ServerRequestInterface $request, array $options): stri
$url['?'][$options['queryParam']] = $redirect;
}

$requestBase = $request->getAttribute('base');
if ($requestBase) {
$url['_base'] = $requestBase;
}

return Router::url($url);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't Router::url() here handle the base path? The test might just need to use Router::setRequest()?

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

use Authorization\Exception\Exception;
use Authorization\Middleware\UnauthorizedHandler\CakeRedirectHandler;
use Cake\Core\Configure;
use Cake\Http\ServerRequestFactory;
use Cake\Routing\Router;
use Cake\TestSuite\TestCase;
Expand Down Expand Up @@ -129,10 +128,10 @@ public function testHandleRedirectWithBasePath()
$handler = new CakeRedirectHandler();
$exception = new Exception();

Configure::write('App.base', '/basedir');
$request = ServerRequestFactory::fromGlobals(
['REQUEST_URI' => '/admin/dashboard']
);
$request = $request->withAttribute('base', '/basedir');

$response = $handler->handle($exception, $request, [
'exceptions' => [
Expand Down