Skip to content

Commit dbcdc0e

Browse files
authored
Require authentication v4 and conflict with older majors (#335)
* Require authentication v4 and conflict with older majors The LoginLink authenticator and identifier follow cakephp/authentication v4's current API (matching method signatures, CakePHP 5.1+). Move the dev requirement to v4 and declare a conflict with anything below 4.0, so consumers cannot pair this plugin with an incompatible authentication major. * Port LoginLink to authentication v4 Authentication v4 made the authenticator's identifier nullable, removed IdentifierCollection, and typed the abstract identifier's default config: - use getIdentifier() instead of the now-nullable identifier property - type LoginLinkIdentifier's default config as a string-keyed array - construct the identifier directly in the authenticator test (no collection)
1 parent 8d7b54d commit dbcdc0e

4 files changed

Lines changed: 15 additions & 16 deletions

File tree

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@
3131
"cakephp/cakephp": "^5.1.1",
3232
"dereuromark/cakephp-shim": "^3.0.0"
3333
},
34+
"conflict": {
35+
"cakephp/authentication": "<4.0.0"
36+
},
3437
"require-dev": {
3538
"fig-r/psr2r-sniffer": "dev-master",
3639
"mobiledetect/mobiledetectlib": "^4.8.09",
3740
"phpunit/phpunit": "^11.5 || ^12.1 || ^13.0",
38-
"cakephp/authentication": "^3.1.0",
41+
"cakephp/authentication": "^4.0.0",
3942
"yangqi/htmldom": "^1.0"
4043
},
4144
"suggest": {

src/Authenticator/LoginLinkAuthenticator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface {
3535
$user = $this->getUserFromToken($token);
3636

3737
if (!$user) {
38-
return new Result(null, ResultInterface::FAILURE_IDENTITY_NOT_FOUND, $this->_identifier->getErrors());
38+
return new Result(null, ResultInterface::FAILURE_IDENTITY_NOT_FOUND, $this->getIdentifier()->getErrors());
3939
}
4040

4141
return new Result($user, ResultInterface::SUCCESS);
@@ -77,7 +77,7 @@ protected function getUserFromToken(string $token): ?EntityInterface {
7777
}
7878

7979
/** @var \Cake\ORM\Entity $identity */
80-
$identity = $this->_identifier->identify([$this->getConfig('identifierKey') => $tokenEntity->user_id]);
80+
$identity = $this->getIdentifier()->identify([$this->getConfig('identifierKey') => $tokenEntity->user_id]);
8181
$email = $tokenEntity->content;
8282
if ($email && $identity && $identity->get('email') && $email !== $identity->get('email')) {
8383
return null;

src/Identifier/LoginLinkIdentifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class LoginLinkIdentifier extends AbstractIdentifier {
1616
/**
1717
* Default configuration.
1818
*
19-
* @var array
19+
* @var array<string, mixed>
2020
*/
2121
protected array $_defaultConfig = [
2222
'idField' => 'id',

tests/TestCase/Authenticator/LoginLinkAuthenticatorTest.php

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
use ArrayAccess;
66
use Authentication\Authenticator\Result;
7-
use Authentication\Identifier\IdentifierCollection;
87
use Cake\Http\ServerRequestFactory;
98
use Cake\TestSuite\TestCase;
109
use Tools\Authenticator\LoginLinkAuthenticator;
10+
use Tools\Identifier\LoginLinkIdentifier;
1111

1212
class LoginLinkAuthenticatorTest extends TestCase {
1313

@@ -22,11 +22,9 @@ class LoginLinkAuthenticatorTest extends TestCase {
2222
];
2323

2424
/**
25-
* Identifier Collection
26-
*
27-
* @var \Authentication\Identifier\IdentifierCollection;
25+
* @var \Tools\Identifier\LoginLinkIdentifier
2826
*/
29-
public $identifiers;
27+
protected $identifier;
3028

3129
/**
3230
* @var \Cake\Http\ServerRequest
@@ -39,12 +37,10 @@ class LoginLinkAuthenticatorTest extends TestCase {
3937
public function setUp(): void {
4038
parent::setUp();
4139

42-
$this->identifiers = new IdentifierCollection([
43-
'Tools.LoginLink' => [
44-
'resolver' => [
45-
'className' => 'Authentication.Orm',
46-
'userModel' => 'ToolsUsers',
47-
],
40+
$this->identifier = new LoginLinkIdentifier([
41+
'resolver' => [
42+
'className' => 'Authentication.Orm',
43+
'userModel' => 'ToolsUsers',
4844
],
4945
]);
5046
}
@@ -65,7 +61,7 @@ public function testAuthenticate() {
6561
'token' => '123',
6662
]);
6763

68-
$authenticator = new LoginLinkAuthenticator($this->identifiers);
64+
$authenticator = new LoginLinkAuthenticator($this->identifier);
6965

7066
$result = $authenticator->authenticate($this->request);
7167
$this->assertInstanceOf(Result::class, $result);

0 commit comments

Comments
 (0)