Browse Source

Include authentication provider instance in Auth.afterIdentify event data.

ADmad 10 years ago
parent
commit
8b746c5ed0

+ 2 - 2
src/Controller/Component/AuthComponent.php

@@ -697,7 +697,7 @@ class AuthComponent extends Component
             $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;
                 }
@@ -769,7 +769,7 @@ class AuthComponent extends Component
             $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;
                 }

+ 4 - 0
tests/TestCase/Controller/Component/AuthComponentTest.php

@@ -1156,6 +1156,10 @@ class AuthComponentTest extends TestCase
         $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;

+ 3 - 0
tests/test_app/TestApp/Auth/TestAuthenticate.php

@@ -27,6 +27,8 @@ class TestAuthenticate extends BaseAuthenticate
 
     public $callStack = [];
 
+    public $authenticationProvider;
+
     public function implementedEvents()
     {
         return [
@@ -43,6 +45,7 @@ class TestAuthenticate extends BaseAuthenticate
     public function afterIdentify(Event $event, array $user)
     {
         $this->callStack[] = __FUNCTION__;
+        $this->authenticationProvider = $event->data[1];
 
         if (!empty($this->modifiedUser)) {
             return $user + ['extra' => 'foo'];