Skip to content

Commit 048648d

Browse files
committed
Merge branch '2.next'
2 parents d8a4965 + 58f97af commit 048648d

File tree

7 files changed

+47
-27
lines changed

7 files changed

+47
-27
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
"homepage": "https://cakephp.org",
1212
"require": {
1313
"cakephp/core": "^4.0",
14+
"laminas/laminas-diactoros": "^2.2.2",
1415
"psr/http-client": "^1.0",
1516
"psr/http-message": "^1.0",
1617
"psr/http-server-handler": "^1.0",
17-
"psr/http-server-middleware": "^1.0",
18-
"zendframework/zend-diactoros": "^2.0"
18+
"psr/http-server-middleware": "^1.0"
1919
},
2020
"require-dev": {
2121
"cakephp/cakephp": "^4.0",

docs/en/authenticators.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ configuring your app as follows::
174174
], [
175175
'controller' => '(jwks)',
176176
]); // connect /.well-known/jwks.json to JwksController
177-
177+
178178
// controller/JwksController.php
179179
public function index()
180180
{
@@ -194,7 +194,7 @@ configuring your app as follows::
194194
$this->set(compact('keys'));
195195
$this->viewBuilder()->setOption('serialize', 'keys');
196196
}
197-
197+
198198
Refer to https://tools.ietf.org/html/rfc7517 or https://auth0.com/docs/tokens/concepts/jwks for
199199
more information about JWKS.
200200

@@ -243,8 +243,13 @@ Configuration options:
243243
- **path**: Path, default is ``/``
244244
- **domain**: Domain, default is an empty string.
245245
- **secure**: Bool, default is ``false``
246-
- **httpOnly**: Bool, default is ``false``
246+
- **httponly**: Bool, default is ``false``
247247
- **value**: Value, default is an empty string.
248+
- **samesite**: String/null The value for the same site attribute.
249+
250+
The defaults for the various options besides ``cookie.name`` will be those
251+
set for the ``Cake\Http\Cookie\Cookie`` class. See `Cookie::setDefaults() <https://api.cakephp.org/4.0/class-Cake.Http.Cookie.Cookie.html#setDefaults>`_
252+
for the default values.
248253

249254
- **fields**: Array that maps ``username`` and ``password`` to the
250255
specified identity fields.

src/AuthenticationService.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,7 @@ public function persistIdentity(ServerRequestInterface $request, ResponseInterfa
247247
}
248248
}
249249

250-
if (!($identity instanceof IdentityInterface)) {
251-
$identity = $this->buildIdentity($identity);
252-
}
250+
$identity = $this->buildIdentity($identity);
253251

254252
return [
255253
'request' => $request->withAttribute($this->getConfig('identityAttribute'), $identity),

src/Authenticator/CookieAuthenticator.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ class CookieAuthenticator extends AbstractAuthenticator implements PersistenceIn
4949
],
5050
'cookie' => [
5151
'name' => 'CookieAuth',
52-
'expire' => null,
53-
'path' => '/',
54-
'domain' => '',
55-
'secure' => false,
56-
'httpOnly' => false,
5752
],
5853
'passwordHasher' => 'Authentication.Default',
5954
];
@@ -215,16 +210,25 @@ public function clearIdentity(ServerRequestInterface $request, ResponseInterface
215210
*/
216211
protected function _createCookie($value): CookieInterface
217212
{
218-
$data = $this->getConfig('cookie');
213+
$options = $this->getConfig('cookie');
214+
$name = $options['name'];
215+
unset($options['name']);
216+
217+
if (array_key_exists('expire', $options)) {
218+
deprecationWarning('Config key `expire` is deprecated, use `expires` instead.');
219+
$options['expires'] = $options['expire'];
220+
unset($options['expire']);
221+
}
222+
if (array_key_exists('httpOnly', $options)) {
223+
deprecationWarning('Config key `httpOnly` is deprecated, use `httponly` instead.');
224+
$options['httponly'] = $options['httpOnly'];
225+
unset($options['httpOnly']);
226+
}
219227

220-
$cookie = new Cookie(
221-
$data['name'],
228+
$cookie = Cookie::create(
229+
$name,
222230
$value,
223-
$data['expire'],
224-
$data['path'],
225-
$data['domain'],
226-
$data['secure'],
227-
$data['httpOnly']
231+
$options
228232
);
229233

230234
return $cookie;

src/Middleware/AuthenticationMiddleware.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
use Authentication\Authenticator\UnauthenticatedException;
2525
use Cake\Core\InstanceConfigTrait;
2626
use InvalidArgumentException;
27+
use Laminas\Diactoros\Response;
28+
use Laminas\Diactoros\Response\RedirectResponse;
29+
use Laminas\Diactoros\Stream;
2730
use Psr\Http\Message\ResponseInterface;
2831
use Psr\Http\Message\ServerRequestInterface;
2932
use Psr\Http\Server\MiddlewareInterface;
3033
use Psr\Http\Server\RequestHandlerInterface;
3134
use RuntimeException;
32-
use Zend\Diactoros\Response;
33-
use Zend\Diactoros\Response\RedirectResponse;
34-
use Zend\Diactoros\Stream;
3535

3636
/**
3737
* Authentication Middleware

tests/TestCase/AuthenticationServiceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,13 @@ public function testPersistIdentityInterface()
396396
{
397397
$request = new ServerRequest();
398398
$response = new Response();
399-
$identity = $this->createMock(IdentityInterface::class);
399+
$identity = new ArrayObject();
400400

401401
$service = new AuthenticationService();
402402

403403
$result = $service->persistIdentity($request, $response, $identity);
404404

405-
$this->assertSame($identity, $result['request']->getAttribute('identity'));
405+
$this->assertInstanceOf(IdentityInterface::class, $result['request']->getAttribute('identity'));
406406
}
407407

408408
/**

tests/TestCase/Authenticator/CookieAuthenticatorTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,10 @@ public function testPersistIdentity()
230230
]);
231231
$response = new Response();
232232

233-
$authenticator = new CookieAuthenticator($identifiers);
233+
Cookie::setDefaults(['samesite' => 'None']);
234+
$authenticator = new CookieAuthenticator($identifiers, [
235+
'cookie' => ['expires' => '2030-01-01 00:00:00'],
236+
]);
234237

235238
$identity = new ArrayObject([
236239
'username' => 'mariano',
@@ -247,6 +250,16 @@ public function testPersistIdentity()
247250
'CookieAuth=%5B%22mariano%22%2C%22%242y%2410%24',
248251
$result['response']->getHeaderLine('Set-Cookie')
249252
);
253+
$this->assertStringContainsString(
254+
'expires=Tue, 01-Jan-2030 00:00:00 GMT;',
255+
$result['response']->getHeaderLine('Set-Cookie')
256+
);
257+
$this->assertStringContainsString(
258+
'samesite=None',
259+
$result['response']->getHeaderLine('Set-Cookie')
260+
);
261+
262+
Cookie::setDefaults(['samesite' => null]);
250263

251264
// Testing that the field is not present
252265
$request = $request->withParsedBody([]);

0 commit comments

Comments
 (0)