Skip to content

Commit 1413003

Browse files
committed
Fix Authentication plugin v4 tutorial corrections
- Use PasswordIdentifier instead of AbstractIdentifier (constants moved in v4) - Fix identifier config format: use className key instead of nested array - Split code-group into separate code blocks for clarity (middleware and service) - Fix line highlighting: {3} -> {4} for User entity import, {8} -> {9} for middleware
1 parent 4537922 commit 1413003

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

docs/en/tutorials-and-examples/cms/authentication.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Because we want to hash the password each time it is set, we'll use a mutator/se
4545
CakePHP will call a convention based setter method any time a property is set in one of your
4646
entities. Let's add a setter for the password in **src/Model/Entity/User.php**:
4747

48-
```php {3,12-18}
48+
```php {4,12-18}
4949
<?php
5050
namespace App\Model\Entity;
5151

@@ -109,7 +109,7 @@ In **src/Application.php**, add the following imports:
109109
use Authentication\AuthenticationService;
110110
use Authentication\AuthenticationServiceInterface;
111111
use Authentication\AuthenticationServiceProviderInterface;
112-
use Authentication\Identifier\AbstractIdentifier;
112+
use Authentication\Identifier\PasswordIdentifier;
113113
use Authentication\Middleware\AuthenticationMiddleware;
114114
use Psr\Http\Message\ServerRequestInterface;
115115
```
@@ -123,11 +123,9 @@ class Application extends BaseApplication
123123
{
124124
```
125125

126-
Then add the following methods:
126+
Then add the following to your `middleware()` method:
127127

128-
::: code-group
129-
130-
```php [middleware()]
128+
```php
131129
// src/Application.php
132130
public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
133131
{
@@ -142,7 +140,9 @@ public function middleware(MiddlewareQueue $middlewareQueue): MiddlewareQueue
142140
}
143141
```
144142

145-
```php [getAuthenticationService()]
143+
Next, add the `getAuthenticationService()` method:
144+
145+
```php
146146
// src/Application.php
147147
public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface
148148
{
@@ -160,8 +160,8 @@ public function getAuthenticationService(ServerRequestInterface $request): Authe
160160
]);
161161

162162
$fields = [
163-
AbstractIdentifier::CREDENTIAL_USERNAME => 'email',
164-
AbstractIdentifier::CREDENTIAL_PASSWORD => 'password',
163+
PasswordIdentifier::CREDENTIAL_USERNAME => 'email',
164+
PasswordIdentifier::CREDENTIAL_PASSWORD => 'password',
165165
];
166166

167167
// Load the authenticators. Session should be first.
@@ -175,18 +175,15 @@ public function getAuthenticationService(ServerRequestInterface $request): Authe
175175
'action' => 'login',
176176
],
177177
'identifier' => [
178-
'Authentication.Password' => [
179-
'fields' => $fields,
180-
],
178+
'className' => 'Authentication.Password',
179+
'fields' => $fields,
181180
],
182181
]);
183182

184183
return $service;
185184
}
186185
```
187186

188-
:::
189-
190187
### Configuring the AppController
191188

192189
In your `AppController` class add the following code:

0 commit comments

Comments
 (0)