Skip to content
Merged
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
10 changes: 9 additions & 1 deletion src/Authenticator/EnvironmentAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace Authentication\Authenticator;

use Authentication\UrlChecker\UrlCheckerTrait;
use Cake\Routing\Router;
use Psr\Http\Message\ServerRequestInterface;

/**
Expand Down Expand Up @@ -114,11 +115,18 @@ protected function _buildLoginUrlErrorResult(ServerRequestInterface $request): R
$uri = $uri->getPath();
}

$loginUrls = (array)$this->getConfig('loginUrl');
foreach ($loginUrls as $key => $loginUrl) {
if (is_array($loginUrl)) {
$loginUrls[$key] = Router::url($loginUrl);
}
}

$errors = [
sprintf(
'Login URL `%s` did not match `%s`.',
$uri,
implode('` or `', (array)$this->getConfig('loginUrl')),
implode('` or `', $loginUrls),
),
];

Expand Down
10 changes: 9 additions & 1 deletion src/Authenticator/FormAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

use Authentication\Identifier\AbstractIdentifier;
use Authentication\UrlChecker\UrlCheckerTrait;
use Cake\Routing\Router;
use Psr\Http\Message\ServerRequestInterface;

/**
Expand Down Expand Up @@ -96,11 +97,18 @@ protected function _buildLoginUrlErrorResult(ServerRequestInterface $request): R
$uri = $uri->getPath();
}

$loginUrls = (array)$this->getConfig('loginUrl');
foreach ($loginUrls as $key => $loginUrl) {
if (is_array($loginUrl)) {
$loginUrls[$key] = Router::url($loginUrl);
}
}

$errors = [
sprintf(
'Login URL `%s` did not match `%s`.',
$uri,
implode('` or `', (array)$this->getConfig('loginUrl')),
implode('` or `', $loginUrls),
),
];

Expand Down
8 changes: 6 additions & 2 deletions tests/TestCase/Authenticator/EnvironmentAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Authentication\Identifier\IdentifierCollection;
use Authentication\Test\TestCase\AuthenticationTestCase as TestCase;
use Cake\Http\ServerRequestFactory;
use Cake\Routing\Router;
use RuntimeException;

class EnvironmentAuthenticatorTest extends TestCase
Expand Down Expand Up @@ -261,10 +262,13 @@ public function testSingleLoginUrlMismatch()
*/
public function testMultipleLoginUrlMismatch()
{
Router::createRouteBuilder('/')
->connect('/{lang}/secure', ['controller' => 'Users', 'action' => 'login']);

$envAuth = new EnvironmentAuthenticator($this->identifiers, [
'loginUrl' => [
'/en/secure',
'/de/secure',
['lang' => 'en', 'controller' => 'Users', 'action' => 'login'],
['lang' => 'de', 'controller' => 'Users', 'action' => 'login'],
],
'fields' => [
'USER_ID',
Expand Down
9 changes: 7 additions & 2 deletions tests/TestCase/Authenticator/FormAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Authentication\Identifier\IdentifierCollection;
use Authentication\Test\TestCase\AuthenticationTestCase as TestCase;
use Cake\Http\ServerRequestFactory;
use Cake\Routing\Router;
use RuntimeException;

class FormAuthenticatorTest extends TestCase
Expand Down Expand Up @@ -156,10 +157,14 @@ public function testMultipleLoginUrlMismatch()
['username' => 'mariano', 'password' => 'password'],
);

Router::createRouteBuilder('/')
->connect('/{lang}/users/login', ['controller' => 'Users', 'action' => 'login']);

$form = new FormAuthenticator($identifiers, [
'urlChecker' => 'Authentication.CakeRouter',
'loginUrl' => [
'/en/users/login',
'/de/users/login',
['lang' => 'en', 'controller' => 'Users', 'action' => 'login'],
['lang' => 'de', 'controller' => 'Users', 'action' => 'login'],
],
]);

Expand Down