Skip to content

Commit df328d0

Browse files
authored
Merge pull request #784 from cakephp/docs
Fix docs for identifier config
2 parents 0c27c60 + 4d359b6 commit df328d0

File tree

4 files changed

+87
-72
lines changed

4 files changed

+87
-72
lines changed

docs/en/authenticators.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ You can also provide a fully custom identifier configuration if needed:
5454
```php
5555
$service->loadAuthenticator('Authentication.PrimaryKeySession', [
5656
'identifier' => [
57-
'Authentication.Token' => [
58-
'tokenField' => 'id',
59-
'dataField' => 'key',
60-
'resolver' => 'Authentication.Orm',
61-
],
57+
'className' => 'Authentication.Token',
58+
'tokenField' => 'id',
59+
'dataField' => 'key',
60+
'resolver' => 'Authentication.Orm',
6261
],
6362
]);
6463
```
@@ -424,10 +423,9 @@ and similar SAML 1.1 implementations. An example configuration is:
424423
// Configure a token identifier that maps `USER_ID` to the
425424
// username column
426425
$identifier = [
427-
'Authentication.Token' => [
428-
'tokenField' => 'username',
429-
'dataField' => 'USER_NAME',
430-
],
426+
'className' => 'Authentication.Token',
427+
'tokenField' => 'username',
428+
'dataField' => 'USER_NAME',
431429
];
432430

433431
$service->loadAuthenticator('Authentication.Environment', [
@@ -537,12 +535,9 @@ $service = new AuthenticationService();
537535

538536
// Define identifiers
539537
$passwordIdentifier = [
540-
'Authentication.Password' => [
541-
'fields' => [
542-
'username' => 'email',
543-
'password' => 'password'
544-
]
545-
],
538+
'className' => 'Authentication.Password',
539+
'username' => 'email',
540+
'password' => 'password'
546541
];
547542

548543
// Load the authenticators leaving Basic as the last one.

docs/en/identifiers.md

Lines changed: 49 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,22 @@ using the Password Identifier looks like:
66

77
```php
88
$identifier = [
9-
'Authentication.Password' => [
10-
'fields' => [
11-
'username' => 'email',
12-
'password' => 'passwd',
13-
],
14-
'resolver' => [
15-
'className' => 'Authentication.Orm',
16-
'userModel' => 'Users',
17-
'finder' => 'active', // default: 'all'
18-
],
19-
'passwordHasher' => [
20-
'className' => 'Authentication.Fallback',
21-
'hashers' => [
22-
'Authentication.Default' => [
23-
'className' => 'Authentication.Legacy',
24-
'hashType' => 'md5',
25-
],
9+
'className' => 'Authentication.Password',
10+
'fields' => [
11+
'username' => 'email',
12+
'password' => 'passwd',
13+
],
14+
'resolver' => [
15+
'className' => 'Authentication.Orm',
16+
'userModel' => 'Users',
17+
'finder' => 'active', // default: 'all'
18+
],
19+
'passwordHasher' => [
20+
'className' => 'Authentication.Fallback',
21+
'hashers' => [
22+
'Authentication.Default' => [
23+
'className' => 'Authentication.Legacy',
24+
'hashType' => 'md5',
2625
],
2726
],
2827
],
@@ -121,37 +120,35 @@ Callback identifiers can either return `null|ArrayAccess` for simple results, or
121120
```php
122121
// A simple callback identifier
123122
$identifier = [
124-
'Authentication.Callback' => [
125-
'callback' => function($data) {
126-
// do identifier logic
127-
128-
// Return an array of the identified user or null for failure.
129-
if ($result) {
130-
return $result;
131-
}
132-
133-
return null;
134-
},
135-
]
123+
'className' => 'Authentication.Callback',
124+
'callback' => function($data) {
125+
// do identifier logic
126+
127+
// Return an array of the identified user or null for failure.
128+
if ($result) {
129+
return $result;
130+
}
131+
132+
return null;
133+
},
136134
];
137135

138136
// Using a result object to return error messages.
139137
$identifier = [
140-
'Authentication.Callback' => [
141-
'callback' => function($data) {
142-
// do identifier logic
143-
144-
if ($result) {
145-
return new Result($result, Result::SUCCESS);
146-
}
147-
148-
return new Result(
149-
null,
150-
Result::FAILURE_OTHER,
151-
['message' => 'Removed user.']
152-
);
153-
},
154-
],
138+
'className' => 'Authentication.Callback',
139+
'callback' => function($data) {
140+
// do identifier logic
141+
142+
if ($result) {
143+
return new Result($result, Result::SUCCESS);
144+
}
145+
146+
return new Result(
147+
null,
148+
Result::FAILURE_OTHER,
149+
['message' => 'Removed user.']
150+
);
151+
},
155152
];
156153
```
157154

@@ -187,13 +184,12 @@ Resolver can be configured using `resolver` config option:
187184

188185
```php
189186
$identifier = [
190-
'Authentication.Password' => [
191-
'resolver' => [
192-
// can be a full class name: \Some\Other\Custom\Resolver::class
193-
'className' => 'MyResolver',
194-
// Pass additional options to the resolver constructor.
195-
'option' => 'value',
196-
],
187+
'className' => 'Authentication.Password',
188+
'resolver' => [
189+
// can be a full class name: \Some\Other\Custom\Resolver::class
190+
'className' => 'MyResolver',
191+
// Pass additional options to the resolver constructor.
192+
'option' => 'value',
197193
],
198194
];
199195
```
@@ -203,8 +199,7 @@ Or pass the constructed resolver directly into the identifier configuration:
203199
```php
204200
$resolver = new \App\Identifier\Resolver\CustomResolver();
205201
$identifier = [
206-
'Authentication.Password' => [
207-
'resolver' => $resolver,
208-
],
202+
'className' => 'Authentication.Password',
203+
'resolver' => $resolver,
209204
];
210205
```

docs/en/index.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ public function getAuthenticationService(ServerRequestInterface $request): Authe
102102
$service->loadAuthenticator('Authentication.Session');
103103
$service->loadAuthenticator('Authentication.Form', [
104104
'identifier' => [
105-
'Authentication.Password' => [
106-
'fields' => $fields,
107-
],
105+
'className' => 'Authentication.Password',
106+
'fields' => $fields,
108107
],
109108
'fields' => $fields,
110109
'loginUrl' => Router::url([

docs/en/upgrade-3-to-4.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ $authenticator = new FormAuthenticator(null);
3838
$service->loadAuthenticator('Authentication.Form', [
3939
'identifier' => 'Authentication.Password',
4040
]);
41+
42+
// Option 4: Configure identifier in authenticator config with identifier options
43+
$service->loadAuthenticator('Authentication.Form', [
44+
'identifier' => [
45+
'className' => 'Authentication.Password',
46+
'fields' => [
47+
'username' => 'email',
48+
'password' => 'password',
49+
],
50+
],
51+
]);
4152
```
4253

4354
#### AuthenticationService Changes
@@ -62,6 +73,21 @@ $service->loadAuthenticator('Authentication.Form', [
6273
]);
6374
```
6475

76+
or
77+
78+
```php
79+
$service = new AuthenticationService();
80+
$service->loadAuthenticator('Authentication.Form', [
81+
'identifier' => [
82+
'className' => 'Authentication.Password',
83+
'fields' => [
84+
'username' => 'email',
85+
'password' => 'password',
86+
],
87+
],
88+
]);
89+
```
90+
6591
### CREDENTIAL Constants Moved
6692

6793
The `CREDENTIAL_USERNAME` and `CREDENTIAL_PASSWORD` constants have been

0 commit comments

Comments
 (0)