Skip to content

Commit 6edbfe6

Browse files
committed
Merge remote-tracking branch 'origin/3.x' into 3.next
2 parents 839e073 + 1366eb4 commit 6edbfe6

20 files changed

+110
-45
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"docs": "https://book.cakephp.org/authentication/3/en/"
2424
},
2525
"require": {
26+
"php": ">=8.1",
2627
"cakephp/http": "^5.0",
2728
"laminas/laminas-diactoros": "^3.0",
2829
"psr/http-client": "^1.0",

docs/en/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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

readme.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CakePHP Authentication
22

3-
![Build Status](https://github.com/cakephp/authentication/actions/workflows/ci.yml/badge.svg?branch=master)
3+
[![CI](https://github.com/cakephp/authentication/actions/workflows/ci.yml/badge.svg)](https://github.com/cakephp/authentication/actions/workflows/ci.yml)
44
[![Latest Stable Version](https://img.shields.io/github/v/release/cakephp/authentication?sort=semver&style=flat-square)](https://packagist.org/packages/cakephp/authentication)
55
[![Total Downloads](https://img.shields.io/packagist/dt/cakephp/authentication?style=flat-square)](https://packagist.org/packages/cakephp/authentication/stats)
66
[![Code Coverage](https://img.shields.io/coveralls/cakephp/authentication/master.svg?style=flat-square)](https://coveralls.io/r/cakephp/authentication?branch=master)
@@ -23,18 +23,12 @@ You can install this plugin into your CakePHP application using
2323
[composer](https://getcomposer.org):
2424

2525
```
26-
php composer.phar require cakephp/authentication
26+
composer require cakephp/authentication
2727
```
2828

29-
Load the plugin by adding the following statement in your project's
30-
`src/Application.php`:
31-
```php
32-
public function bootstrap(): void
33-
{
34-
parent::bootstrap();
35-
36-
$this->addPlugin('Authentication');
37-
}
29+
Then load the plugin:
30+
```
31+
bin/cake plugin load Authentication
3832
```
3933

4034
## Documentation
@@ -43,4 +37,6 @@ Documentation for this plugin can be found in the [CakePHP Cookbook](https://boo
4337

4438
## IDE compatibility improvements
4539

46-
For `AuthenticationService::loadIdentifier()` you an find an IdeHelper task in [IdeHelperExtra plugin](https://github.com/dereuromark/cakephp-ide-helper-extra/).
40+
There are IdeHelper tasks in [IdeHelperExtra plugin](https://github.com/dereuromark/cakephp-ide-helper-extra/) to provide auto-complete:
41+
- `AuthenticationService::loadAuthenticator()`
42+
- `IdentifierCollection::load()`

src/AuthenticationService.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Authentication\Identifier\IdentifierCollection;
2727
use Authentication\Identifier\IdentifierInterface;
2828
use Cake\Core\InstanceConfigTrait;
29+
use Cake\Routing\Router;
2930
use InvalidArgumentException;
3031
use Psr\Http\Message\ResponseInterface;
3132
use 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
}

src/Authenticator/CookieAuthenticator.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
8484

8585
$identity = $this->_identifier->identify(compact('username'));
8686

87-
if (empty($identity)) {
87+
if (!$identity) {
8888
return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identifier->getErrors());
8989
}
9090

@@ -134,9 +134,14 @@ protected function _createPlainToken(ArrayAccess|array $identity): string
134134
$usernameField = $this->getConfig('fields.username');
135135
$passwordField = $this->getConfig('fields.password');
136136

137-
$salt = $this->getConfig('salt', '');
137+
if ($identity[$usernameField] === null || $identity[$passwordField] === null) {
138+
throw new InvalidArgumentException(
139+
sprintf('Fields %s cannot be found in entity', '`' . $usernameField . '`/`' . $passwordField . '`'),
140+
);
141+
}
138142

139143
$value = $identity[$usernameField] . $identity[$passwordField];
144+
$salt = $this->getConfig('salt', '');
140145

141146
if ($salt === false) {
142147
return $value;

src/Authenticator/EnvironmentAuthenticator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
137137
return $this->_buildLoginUrlErrorResult($request);
138138
}
139139
$data = $this->_getData($request);
140-
if (empty($data)) {
140+
if (!$data) {
141141
return new Result(null, Result::FAILURE_CREDENTIALS_MISSING, [
142142
'Environment credentials not found',
143143
]);
@@ -147,7 +147,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
147147

148148
$user = $this->_identifier->identify($data);
149149

150-
if (empty($user)) {
150+
if (!$user) {
151151
return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identifier->getErrors());
152152
}
153153

src/Authenticator/FormAuthenticator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
130130

131131
$user = $this->_identifier->identify($data);
132132

133-
if (empty($user)) {
133+
if (!$user) {
134134
return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identifier->getErrors());
135135
}
136136

src/Authenticator/HttpDigestAuthenticator.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
9898
AbstractIdentifier::CREDENTIAL_USERNAME => $digest['username'],
9999
]);
100100

101-
if (empty($user)) {
101+
if (!$user) {
102102
return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND);
103103
}
104104

@@ -132,13 +132,13 @@ protected function _getDigest(ServerRequestInterface $request): ?array
132132
{
133133
$server = $request->getServerParams();
134134
$digest = empty($server['PHP_AUTH_DIGEST']) ? null : $server['PHP_AUTH_DIGEST'];
135-
if (empty($digest) && function_exists('apache_request_headers')) {
135+
if (!$digest && function_exists('apache_request_headers')) {
136136
$headers = apache_request_headers();
137137
if (!empty($headers['Authorization']) && substr($headers['Authorization'], 0, 7) === 'Digest ') {
138138
$digest = substr($headers['Authorization'], 7);
139139
}
140140
}
141-
if (empty($digest)) {
141+
if (!$digest) {
142142
return null;
143143
}
144144

@@ -165,7 +165,7 @@ public function parseAuthData(string $digest): ?array
165165
unset($req[$i[1]]);
166166
}
167167

168-
if (empty($req)) {
168+
if (!$req) {
169169
return $keys;
170170
}
171171

src/Authenticator/JwtAuthenticator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
110110
$subjectKey => $result[$subjectKey],
111111
]);
112112

113-
if (empty($user)) {
113+
if (!$user) {
114114
return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND, $this->_identifier->getErrors());
115115
}
116116

src/Authenticator/SessionAuthenticator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SessionAuthenticator extends AbstractAuthenticator implements PersistenceI
3131
* Default config for this object.
3232
* - `fields` The fields to use to verify a user by.
3333
* - `sessionKey` Session key.
34-
* - `identify` Whether or not to identify user data stored in a session. This is
34+
* - `identify` Whether to identify user data stored in a session. This is
3535
* useful if you want to remotely end sessions that have a different password stored,
3636
* or if your identification logic needs additional conditions before a user can login.
3737
*
@@ -60,7 +60,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
6060
$session = $request->getAttribute('session');
6161
$user = $session->read($sessionKey);
6262

63-
if (empty($user)) {
63+
if (!$user) {
6464
return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND);
6565
}
6666

@@ -71,7 +71,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
7171
}
7272
$user = $this->_identifier->identify($credentials);
7373

74-
if (empty($user)) {
74+
if (!$user) {
7575
return new Result(null, Result::FAILURE_CREDENTIALS_INVALID);
7676
}
7777
}

0 commit comments

Comments
 (0)