Skip to content

Commit

Permalink
Include authentication provider instance in Auth.afterIdentify event …
Browse files Browse the repository at this point in the history
…data.
  • Loading branch information
ADmad committed Dec 2, 2015
1 parent 754f4a2 commit 8b746c5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Controller/Component/AuthComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ protected function _getUser()
$result = $auth->getUser($this->request);
if (!empty($result) && is_array($result)) {
$this->_authenticationProvider = $auth;
$event = $this->dispatchEvent('Auth.afterIdentify', [$result]);
$event = $this->dispatchEvent('Auth.afterIdentify', [$result, $auth]);
if ($event->result !== null) {
$result = $event->result;
}
Expand Down Expand Up @@ -769,7 +769,7 @@ public function identify()
$result = $auth->authenticate($this->request, $this->response);
if (!empty($result) && is_array($result)) {
$this->_authenticationProvider = $auth;
$event = $this->dispatchEvent('Auth.afterIdentify', [$result]);
$event = $this->dispatchEvent('Auth.afterIdentify', [$result, $auth]);
if ($event->result !== null) {
return $event->result;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase/Controller/Component/AuthComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,10 @@ public function testEventTriggering()
$this->assertEquals($expected, $authObject->callStack);
$expected = ['id' => 1, 'username' => 'admad'];
$this->assertEquals($expected, $user);
$this->assertInstanceOf(
'TestApp\Auth\TestAuthenticate',
$authObject->authenticationProvider
);

// Callback for Auth.afterIdentify returns a value
$authObject->modifiedUser = true;
Expand Down
3 changes: 3 additions & 0 deletions tests/test_app/TestApp/Auth/TestAuthenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class TestAuthenticate extends BaseAuthenticate

public $callStack = [];

public $authenticationProvider;

public function implementedEvents()
{
return [
Expand All @@ -43,6 +45,7 @@ public function authenticate(Request $request, Response $response)
public function afterIdentify(Event $event, array $user)
{
$this->callStack[] = __FUNCTION__;
$this->authenticationProvider = $event->data[1];

if (!empty($this->modifiedUser)) {
return $user + ['extra' => 'foo'];
Expand Down

0 comments on commit 8b746c5

Please sign in to comment.