@@ -182,7 +182,7 @@ public function getAuthenticationService(ServerRequestInterface $request): Authe
182182 // ...
183183 $service->loadAuthenticator('Authentication.Jwt', [
184184 'identifier' => 'Authentication.JwtSubject',
185- 'secretKey' => file_get_contents(CONFIG . '/ jwt.key'),
185+ 'secretKey' => file_get_contents(CONFIG . 'jwt.key'),
186186 'algorithm' => 'RS256',
187187 'returnPayload' => false
188188 ]);
@@ -196,11 +196,11 @@ In your `UsersController`:
196196``` php
197197use Firebase\JWT\JWT;
198198
199- public function login()
199+ public function login(): void
200200{
201201 $result = $this->Authentication->getResult();
202202 if ($result->isValid()) {
203- $privateKey = file_get_contents(CONFIG . '/ jwt.key');
203+ $privateKey = file_get_contents(CONFIG . 'jwt.key');
204204 $user = $result->getData();
205205 $payload = [
206206 'iss' => 'myapp',
@@ -260,16 +260,19 @@ distribute it via a JWKS endpoint by configuring your app as follows:
260260``` php
261261// config/routes.php
262262$builder->setExtensions('json');
263- $builder->connect('/.well-known/: controller/* ', [
263+ $builder->connect('/.well-known/{ controller} ', [
264264 'action' => 'index',
265265], [
266- 'controller' => '(jwks)',
266+ 'controller' => 'jwks',
267+ 'pass' => [],
267268]); // connect /.well-known/jwks.json to JwksController
268269
269270// controller/JwksController.php
271+ use Firebase\JWT\JWT;
272+
270273public function index()
271274{
272- $pubKey = file_get_contents(CONFIG . './ jwt.pem');
275+ $pubKey = file_get_contents(CONFIG . 'jwt.pem');
273276 $res = openssl_pkey_get_public($pubKey);
274277 $detail = openssl_pkey_get_details($res);
275278 $key = [
@@ -313,7 +316,7 @@ Configuration options:
313316
314317- ** realm** : Default is ` null `
315318- ** qop** : Default is ` auth `
316- - ** nonce** : Default is ` uniqid(''), `
319+ - ** nonce** : Default is ` uniqid('') `
317320- ** opaque** : Default is ` null `
318321
319322## Cookie Authenticator aka "Remember Me"
@@ -344,7 +347,7 @@ Configuration options:
344347 - ** samesite** : String/null The value for the same site attribute.
345348
346349 The defaults for the various options besides ` cookie.name ` will be those
347- set for the ` Cake\Http\Cookie\Cookie ` class. See [ Cookie::setDefaults()] ( https://api.cakephp.org/4.0 /class-Cake.Http.Cookie.Cookie.html#setDefaults )
350+ set for the ` Cake\Http\Cookie\Cookie ` class. See [ Cookie::setDefaults()] ( https://api.cakephp.org/5 /class-Cake.Http.Cookie.Cookie.html#setDefaults )
348351 for the default values.
349352
350353- ** fields** : Array that maps ` username ` and ` password ` to the
@@ -369,16 +372,16 @@ Configuration options:
369372The cookie authenticator can be added to a Form & Session based
370373authentication system. Cookie authentication will automatically re-login users
371374after their session expires for as long as the cookie is valid. If a user is
372- explicity logged out via ` AuthenticationComponent::logout() ` the
375+ explicitly logged out via ` AuthenticationComponent::logout() ` the
373376authentication cookie is ** also destroyed** . An example configuration would be:
374377
375378``` php
376379// In Application::getAuthenticationService()
377380
378381// Reuse fields in multiple authenticators.
379382$fields = [
380- AbstractIdentifier ::CREDENTIAL_USERNAME => 'email',
381- AbstractIdentifier ::CREDENTIAL_PASSWORD => 'password',
383+ PasswordIdentifier ::CREDENTIAL_USERNAME => 'email',
384+ PasswordIdentifier ::CREDENTIAL_PASSWORD => 'password',
382385];
383386
384387// Put form authentication first so that users can re-login via
@@ -389,9 +392,7 @@ $service->loadAuthenticator('Authentication.Form', [
389392 'loginUrl' => '/users/login',
390393]);
391394// Then use sessions if they are active.
392- $service->loadAuthenticator('Authentication.Session', [
393- 'identifier' => 'Authentication.Password',
394- ]);
395+ $service->loadAuthenticator('Authentication.Session');
395396
396397// If the user is on the login page, check for a cookie as well.
397398$service->loadAuthenticator('Authentication.Cookie', [
@@ -441,9 +442,6 @@ $service->loadAuthenticator('Authentication.Environment', [
441442]);
442443```
443444
444- ::: info Added in version 2.10.0
445- ` EnvironmentAuthenticator ` was added.
446- :::
447445
448446## Events
449447
@@ -549,9 +547,7 @@ $passwordIdentifier = [
549547];
550548
551549// Load the authenticators leaving Basic as the last one.
552- $service->loadAuthenticator('Authentication.Session', [
553- 'identifier' => $passwordIdentifier,
554- ]);
550+ $service->loadAuthenticator('Authentication.Session');
555551$service->loadAuthenticator('Authentication.Form', [
556552 'identifier' => $passwordIdentifier,
557553]);
@@ -589,7 +585,7 @@ Then in your controller's login method you can use `getLoginRedirect()` to get
589585the redirect target safely from the query string parameter:
590586
591587``` php
592- public function login()
588+ public function login(): ?\Cake\Http\Response
593589{
594590 $result = $this->Authentication->getResult();
595591
@@ -600,8 +596,11 @@ public function login()
600596 if (!$target) {
601597 $target = ['controller' => 'Pages', 'action' => 'display', 'home'];
602598 }
599+
603600 return $this->redirect($target);
604601 }
602+
603+ return null;
605604}
606605```
607606
@@ -622,7 +621,7 @@ public function getAuthenticationService(
622621
623622 // Configuration common to both the API and web goes here.
624623
625- if ($request->getParam('prefix') == 'Api') {
624+ if ($request->getParam('prefix') === 'Api') {
626625 // Include API specific authenticators
627626 } else {
628627 // Web UI specific authenticators.
0 commit comments