Skip to content

Commit f2c57de

Browse files
committed
Merge branch '2.x' into 2.next
2 parents d112141 + 6e6c06a commit f2c57de

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

.github/workflows/stale.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- uses: actions/stale@v5
13+
- uses: actions/stale@v6
1414
with:
1515
repo-token: ${{ secrets.GITHUB_TOKEN }}
1616
stale-issue-message: 'This issue is stale because it has been open for 120 days with no activity. Remove the `stale` label or comment or this will be closed in 15 days'

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@ public function bootstrap(): void
4040
## Documentation
4141

4242
Documentation for this plugin can be found in the [CakePHP Cookbook](https://book.cakephp.org/authentication/2/en/).
43+
44+
## IDE compatibility improvements
45+
46+
For `AuthenticationService::loadIdentifier()` you an find an IdeHelper task in [IdeHelperExtra plugin](https://github.com/dereuromark/cakephp-ide-helper-extra/).

src/Authenticator/SessionAuthenticator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class SessionAuthenticator extends AbstractAuthenticator implements PersistenceI
3131
* Default config for this object.
3232
* - `fields` The fields to use to verify a user by.
3333
* - `sessionKey` Session key.
34-
* - `identify` Whether or not to identify user data stored in a session.
34+
* - `identify` Whether or not to identify user data stored in a session. This is
35+
* useful if you want to remotely end sessions that have a different password stored,
36+
* or if your identification logic needs additional conditions before a user can login.
3537
*
3638
* @var array
3739
*/

tests/TestCase/AuthenticationServiceTest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use Cake\Http\ServerRequest;
3333
use Cake\Http\ServerRequestFactory;
3434
use Cake\Http\Uri;
35+
use Cake\I18n\FrozenTime;
3536
use Psr\Http\Message\RequestInterface;
3637
use Psr\Http\Message\ResponseInterface;
3738
use Psr\Http\Message\ServerRequestInterface;
@@ -135,6 +136,58 @@ public function testAuthenticateWithChallengeDisabled()
135136
$this->assertFalse($result->isValid());
136137
}
137138

139+
/**
140+
* Integration test for session auth + identify always getting a fresh user record.
141+
*
142+
* @return void
143+
*/
144+
public function testAuthenticationWithSessionIdentify()
145+
{
146+
$users = $this->fetchTable('Users');
147+
$user = $users->get(1);
148+
149+
$request = ServerRequestFactory::fromGlobals([
150+
'SERVER_NAME' => 'example.com',
151+
'REQUEST_URI' => '/testpath',
152+
]);
153+
$request->getSession()->write('Auth', [
154+
'username' => $user->username,
155+
'password' => $user->password,
156+
]);
157+
158+
$factory = function () {
159+
return new AuthenticationService([
160+
'identifiers' => [
161+
'Authentication.Password',
162+
],
163+
'authenticators' => [
164+
'Authentication.Session' => [
165+
'identify' => true,
166+
],
167+
],
168+
]);
169+
};
170+
$service = $factory();
171+
$result = $service->authenticate($request);
172+
$this->assertTrue($result->isValid());
173+
174+
$dateValue = new FrozenTime('2022-01-01 10:11:12');
175+
$identity = $result->getData();
176+
$this->assertEquals($identity->username, $user->username);
177+
$this->assertNotEquals($identity->created, $dateValue);
178+
179+
// Update the user so that we can ensure session is reading from the db.
180+
$user->created = $dateValue;
181+
$users->saveOrFail($user);
182+
183+
$service = $factory();
184+
$result = $service->authenticate($request);
185+
$this->assertTrue($result->isValid());
186+
$identity = $result->getData();
187+
$this->assertEquals($identity->username, $user->username);
188+
$this->assertEquals($identity->created, $dateValue);
189+
}
190+
138191
/**
139192
* testLoadAuthenticatorException
140193
*/

0 commit comments

Comments
 (0)