Skip to content

Commit 8be769c

Browse files
committed
Fix documentation issues for 4.x
- Update AbstractIdentifier::CREDENTIAL_* to PasswordIdentifier::CREDENTIAL_* - Add missing return types to code examples (initialize(), _setPassword()) - Fix broken tutorial link to use absolute CakePHP Book URL - Replace deprecated strpos() with str_starts_with() - Update API link from CakePHP 4.0 to 5 - Remove misleading identifier config from Session authenticator examples - Remove outdated "Added in version 2.10.0" notes - Add missing use statement for JWT in JwksController example - Fix typo in jwt.pem path (./jwt.pem -> /jwt.pem) - Use strict comparison (===) instead of loose (==) - Add missing MiddlewareQueue type hints in migration guide - Remove unused ResponseInterface import - Add missing documentation links in contents.md (redirect-validation, upgrade-3-to-4)
1 parent 46240e1 commit 8be769c

File tree

6 files changed

+25
-34
lines changed

6 files changed

+25
-34
lines changed

docs/en/authenticators.md

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,11 @@ $builder->connect('/.well-known/:controller/*', [
267267
]); // connect /.well-known/jwks.json to JwksController
268268

269269
// controller/JwksController.php
270+
use Firebase\JWT\JWT;
271+
270272
public function index()
271273
{
272-
$pubKey = file_get_contents(CONFIG . './jwt.pem');
274+
$pubKey = file_get_contents(CONFIG . '/jwt.pem');
273275
$res = openssl_pkey_get_public($pubKey);
274276
$detail = openssl_pkey_get_details($res);
275277
$key = [
@@ -344,7 +346,7 @@ Configuration options:
344346
- **samesite**: String/null The value for the same site attribute.
345347

346348
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)
349+
set for the `Cake\Http\Cookie\Cookie` class. See [Cookie::setDefaults()](https://api.cakephp.org/5/class-Cake.Http.Cookie.Cookie.html#setDefaults)
348350
for the default values.
349351

350352
- **fields**: Array that maps `username` and `password` to the
@@ -377,8 +379,8 @@ authentication cookie is **also destroyed**. An example configuration would be:
377379

378380
// Reuse fields in multiple authenticators.
379381
$fields = [
380-
AbstractIdentifier::CREDENTIAL_USERNAME => 'email',
381-
AbstractIdentifier::CREDENTIAL_PASSWORD => 'password',
382+
PasswordIdentifier::CREDENTIAL_USERNAME => 'email',
383+
PasswordIdentifier::CREDENTIAL_PASSWORD => 'password',
382384
];
383385

384386
// Put form authentication first so that users can re-login via
@@ -389,9 +391,7 @@ $service->loadAuthenticator('Authentication.Form', [
389391
'loginUrl' => '/users/login',
390392
]);
391393
// Then use sessions if they are active.
392-
$service->loadAuthenticator('Authentication.Session', [
393-
'identifier' => 'Authentication.Password',
394-
]);
394+
$service->loadAuthenticator('Authentication.Session');
395395

396396
// If the user is on the login page, check for a cookie as well.
397397
$service->loadAuthenticator('Authentication.Cookie', [
@@ -441,9 +441,6 @@ $service->loadAuthenticator('Authentication.Environment', [
441441
]);
442442
```
443443

444-
::: info Added in version 2.10.0
445-
`EnvironmentAuthenticator` was added.
446-
:::
447444

448445
## Events
449446

@@ -549,9 +546,7 @@ $passwordIdentifier = [
549546
];
550547

551548
// Load the authenticators leaving Basic as the last one.
552-
$service->loadAuthenticator('Authentication.Session', [
553-
'identifier' => $passwordIdentifier,
554-
]);
549+
$service->loadAuthenticator('Authentication.Session');
555550
$service->loadAuthenticator('Authentication.Form', [
556551
'identifier' => $passwordIdentifier,
557552
]);
@@ -622,7 +617,7 @@ public function getAuthenticationService(
622617

623618
// Configuration common to both the API and web goes here.
624619

625-
if ($request->getParam('prefix') == 'Api') {
620+
if ($request->getParam('prefix') === 'Api') {
626621
// Include API specific authenticators
627622
} else {
628623
// Web UI specific authenticators.

docs/en/contents.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
- [Testing with Authentication](testing)
1313
- [User Impersonation](impersonation)
1414
- [URL Checkers](url-checkers)
15+
- [Redirect Validation](redirect-validation)
1516
- [View Helper](view-helper)
1617
- [Migration from the AuthComponent](migration-from-the-authcomponent)
1718
- [Upgrading from 2.x to 3.x](upgrade-2-to-3)
19+
- [Upgrading from 3.x to 4.x](upgrade-3-to-4)

docs/en/impersonation.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
# User Impersonation
22

3-
::: info Added in version 2.10.0
4-
User impersonation was added.
5-
:::
6-
73
After deploying your application, you may occasionally need to
84
'impersonate' another user in order to debug problems that your customers report
95
or to see the application in the state that your customers are seeing it.

docs/en/index.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ imports:
2626
use Authentication\AuthenticationService;
2727
use Authentication\AuthenticationServiceInterface;
2828
use Authentication\AuthenticationServiceProviderInterface;
29-
use Authentication\Identifier\AbstractIdentifier;
29+
use Authentication\Identifier\PasswordIdentifier;
3030
use Authentication\Middleware\AuthenticationMiddleware;
3131
use Cake\Http\MiddlewareQueue;
3232
use Cake\Routing\Router;
@@ -93,8 +93,8 @@ public function getAuthenticationService(ServerRequestInterface $request): Authe
9393
]);
9494

9595
$fields = [
96-
AbstractIdentifier::CREDENTIAL_USERNAME => 'email',
97-
AbstractIdentifier::CREDENTIAL_PASSWORD => 'password',
96+
PasswordIdentifier::CREDENTIAL_USERNAME => 'email',
97+
PasswordIdentifier::CREDENTIAL_PASSWORD => 'password',
9898
];
9999

100100
// Load the authenticators. Session should be first.
@@ -135,7 +135,7 @@ Next, in your `AppController` load the [Authentication Component](authentication
135135

136136
``` php
137137
// in src/Controller/AppController.php
138-
public function initialize()
138+
public function initialize(): void
139139
{
140140
parent::initialize();
141141

@@ -156,7 +156,7 @@ $this->Authentication->allowUnauthenticated(['view', 'index']);
156156
## Building a Login Action
157157

158158
Once you have the middleware applied to your application you'll need a way for
159-
users to login. Please ensure your database has been created with the Users table structure used in [tutorial](tutorials-and-examples/cms/database). First generate a Users model and controller with bake:
159+
users to login. Please ensure your database has been created with the Users table structure used in the [CMS tutorial](https://book.cakephp.org/5/en/tutorials-and-examples/cms/database.html). First generate a Users model and controller with bake:
160160

161161
``` bash
162162
bin/cake bake model Users
@@ -240,9 +240,10 @@ class User extends Entity
240240
// ... other methods
241241

242242
// Automatically hash passwords when they are changed.
243-
protected function _setPassword(string $password)
243+
protected function _setPassword(string $password): string
244244
{
245245
$hasher = new DefaultPasswordHasher();
246+
246247
return $hasher->hash($password);
247248
}
248249
}

docs/en/middleware.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function getAuthenticationService(ServerRequestInterface $request): Authe
3737
$path = $request->getPath();
3838

3939
$service = new AuthenticationService();
40-
if (strpos($path, '/api') === 0) {
40+
if (str_starts_with($path, '/api')) {
4141
// Accept API tokens only
4242
$service->loadAuthenticator('Authentication.Token', [
4343
'identifier' => 'Authentication.Token',

docs/en/migration-from-the-authcomponent.md

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ use Authentication\AuthenticationService;
7575
use Authentication\AuthenticationServiceInterface;
7676
use Authentication\AuthenticationServiceProviderInterface;
7777
use Authentication\Middleware\AuthenticationMiddleware;
78-
use Psr\Http\Message\ResponseInterface;
7978
use Psr\Http\Message\ServerRequestInterface;
8079

8180
// Add the authentication interface.
@@ -101,7 +100,7 @@ Next add the `AuthenticationMiddleware` to your application:
101100

102101
``` php
103102
// in src/Application.php
104-
public function middleware($middlewareQueue)
103+
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
105104
{
106105
// Various other middlewares for error handling, routing etc. added here.
107106

@@ -147,13 +146,11 @@ $service = new AuthenticationService();
147146
],
148147
];
149148

150-
// Load the authenticators
151-
$service->loadAuthenticator('Authentication.Session', [
152-
'identifier' => $passwordIdentifier,
153-
]);
154-
$service->loadAuthenticator('Authentication.Form', [
155-
'identifier' => $passwordIdentifier,
156-
]);
149+
// Load the authenticators. Session should be first.
150+
$service->loadAuthenticator('Authentication.Session');
151+
$service->loadAuthenticator('Authentication.Form', [
152+
'identifier' => $passwordIdentifier,
153+
]);
157154
```
158155

159156
If you have customized the `userModel` you can use the following

0 commit comments

Comments
 (0)