Skip to content

Commit 8f0756d

Browse files
committed
refactor authentication configuration and update deprecation warnings
1 parent f5939e4 commit 8f0756d

File tree

3 files changed

+52
-41
lines changed

3 files changed

+52
-41
lines changed

config/users.php

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,34 @@
210210
'Form' => [
211211
'className' => 'CakeDC/Auth.Form',
212212
'urlChecker' => 'Authentication.CakeRouter',
213+
'identifier' => [
214+
'Authentication.Password' => [
215+
'fields' => [
216+
'username' => ['username', 'email'],
217+
'password' => 'password',
218+
],
219+
'resolver' => [
220+
'className' => 'Authentication.Orm',
221+
'finder' => 'active',
222+
],
223+
],
224+
],
213225
],
214226
'Token' => [
215227
'className' => 'Authentication.Token',
216228
'skipTwoFactorVerify' => true,
217229
'header' => null,
218230
'queryParam' => 'api_key',
219231
'tokenPrefix' => null,
232+
'identifier' => [
233+
'Authentication.Token' => [
234+
'tokenField' => 'api_token',
235+
'resolver' => [
236+
'className' => 'Authentication.Orm',
237+
'finder' => 'active',
238+
],
239+
],
240+
],
220241
],
221242
'Cookie' => [
222243
'className' => 'CakeDC/Auth.Cookie',
@@ -231,6 +252,11 @@
231252
'Social' => [
232253
'className' => 'CakeDC/Users.Social',
233254
'skipTwoFactorVerify' => true,
255+
'identifier' => [
256+
'CakeDC/Users.Social' => [
257+
'authFinder' => 'active',
258+
],
259+
],
234260
],
235261
'SocialPendingEmail' => [
236262
'className' => 'CakeDC/Users.SocialPendingEmail',
@@ -244,31 +270,6 @@
244270
],
245271
]
246272
],
247-
'Identifiers' => [
248-
'Password' => [
249-
'className' => 'Authentication.Password',
250-
'fields' => [
251-
'username' => ['username', 'email'],
252-
'password' => 'password',
253-
],
254-
'resolver' => [
255-
'className' => 'Authentication.Orm',
256-
'finder' => 'active',
257-
],
258-
],
259-
'Social' => [
260-
'className' => 'CakeDC/Users.Social',
261-
'authFinder' => 'active',
262-
],
263-
'Token' => [
264-
'className' => 'Authentication.Token',
265-
'tokenField' => 'api_token',
266-
'resolver' => [
267-
'className' => 'Authentication.Orm',
268-
'finder' => 'active',
269-
],
270-
],
271-
],
272273
'Authorization' => [
273274
'enable' => true,
274275
'serviceLoader' => \CakeDC\Users\Loader\AuthorizationServiceLoader::class,

src/Controller/Component/LoginComponent.php

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ protected function afterIdentifyUser($user)
165165
$userId = $user['id'] ?? null;
166166
Log::info(
167167
"Unsafe redirect `$queryRedirect` ignored, user id `{$userId}` " .
168-
"redirected to `$redirectUrl` after successful login",
168+
"redirected to `$redirectUrl` after successful login",
169169
);
170170
$queryRedirect = $redirectUrl;
171171
}
@@ -188,22 +188,20 @@ protected function afterIdentifyUser($user)
188188
*/
189189
protected function handlePasswordRehash($service, $user, \Cake\Http\ServerRequest $request)
190190
{
191-
$indentifiersNames = (array)Configure::read('Auth.PasswordRehash.identifiers');
192-
foreach ($indentifiersNames as $indentifierName) {
193-
/**
194-
* @var \Authentication\Identifier\AbstractIdentifier|null $checker
195-
*/
196-
$checker = $service->identifiers()->get($indentifierName);
197-
if (!$checker || method_exists($checker, 'needsPasswordRehash') && !$checker->needsPasswordRehash()) {
198-
continue;
199-
}
200-
$passwordField = $checker->getConfig('fields.password', 'password');
201-
$password = $request->getData($passwordField);
202-
$user->set($passwordField, $password);
203-
$user->setDirty('modified');
204-
$this->getController()->getUsersTable()->save($user);
205-
break;
191+
/**
192+
* @var \Authentication\Identifier\AbstractIdentifier|null $checker
193+
*/
194+
$checker = $service->getIdentificationProvider();
195+
196+
if (!$checker || method_exists($checker, 'needsPasswordRehash') && !$checker->needsPasswordRehash()) {
197+
return;
206198
}
199+
200+
$passwordField = $checker->getConfig('fields.password', 'password');
201+
$password = $request->getData($passwordField);
202+
$user->set($passwordField, $password);
203+
$user->setDirty('modified');
204+
$this->getController()->getUsersTable()->save($user);
207205
}
208206

209207
/**

src/Loader/AuthenticationServiceLoader.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ public function __invoke(ServerRequestInterface $request)
5252
protected function loadIdentifiers($service)
5353
{
5454
$identifiers = Configure::read('Auth.Identifiers');
55+
56+
if (empty($identifiers)) {
57+
return;
58+
}
59+
60+
deprecationWarning(
61+
'15.2.0',
62+
'Configuring identifiers globally via `Auth.Identifiers` is deprecated. ' .
63+
'Please move each identifier\'s configuration into the `identifier` key within its specific authenticator under `Auth.Authenticators`. ' .
64+
'For example, the `Auth.Identifiers.Password` configuration should now be placed inside `Auth.Authenticators.Form.identifier`.'
65+
);
66+
5567
foreach ($identifiers as $key => $item) {
5668
[$identifier, $options] = $this->_getItemLoadData($item, $key);
5769

0 commit comments

Comments
 (0)