diff --git a/app/code/Magento/Integration/Model/CustomerTokenService.php b/app/code/Magento/Integration/Model/CustomerTokenService.php
index 3c245804a9f6e..cc717a2b3ec08 100644
--- a/app/code/Magento/Integration/Model/CustomerTokenService.php
+++ b/app/code/Magento/Integration/Model/CustomerTokenService.php
@@ -14,6 +14,7 @@
use Magento\Integration\Model\ResourceModel\Oauth\Token\CollectionFactory as TokenCollectionFactory;
use Magento\Integration\Model\Oauth\Token\RequestThrottler;
use Magento\Framework\Exception\AuthenticationException;
+use Magento\Framework\Event\ManagerInterface;
class CustomerTokenService implements \Magento\Integration\Api\CustomerTokenServiceInterface
{
@@ -48,6 +49,11 @@ class CustomerTokenService implements \Magento\Integration\Api\CustomerTokenServ
*/
private $requestThrottler;
+ /**
+ * @var Magento\Framework\Event\ManagerInterface
+ */
+ private $eventManager;
+
/**
* Initialize service
*
@@ -55,17 +61,21 @@ class CustomerTokenService implements \Magento\Integration\Api\CustomerTokenServ
* @param AccountManagementInterface $accountManagement
* @param TokenCollectionFactory $tokenModelCollectionFactory
* @param \Magento\Integration\Model\CredentialsValidator $validatorHelper
+ * @param \Magento\Framework\Event\ManagerInterface $eventManager
*/
public function __construct(
TokenModelFactory $tokenModelFactory,
AccountManagementInterface $accountManagement,
TokenCollectionFactory $tokenModelCollectionFactory,
- CredentialsValidator $validatorHelper
+ CredentialsValidator $validatorHelper,
+ ManagerInterface $eventManager = null
) {
$this->tokenModelFactory = $tokenModelFactory;
$this->accountManagement = $accountManagement;
$this->tokenModelCollectionFactory = $tokenModelCollectionFactory;
$this->validatorHelper = $validatorHelper;
+ $this->eventManager = $eventManager ?: \Magento\Framework\App\ObjectManager::getInstance()
+ ->get(ManagerInterface::class);
}
/**
@@ -86,6 +96,7 @@ public function createCustomerAccessToken($username, $password)
)
);
}
+ $this->eventManager->dispatch('customer_login', ['customer' => $customerDataObject]);
$this->getRequestThrottler()->resetAuthenticationFailuresCount($username, RequestThrottler::USER_TYPE_CUSTOMER);
return $this->tokenModelFactory->create()->createCustomerToken($customerDataObject->getId())->getToken();
}
diff --git a/app/code/Magento/Integration/Test/Unit/Model/CustomerTokenServiceTest.php b/app/code/Magento/Integration/Test/Unit/Model/CustomerTokenServiceTest.php
index 1a7c819343294..1bc7d4247080f 100644
--- a/app/code/Magento/Integration/Test/Unit/Model/CustomerTokenServiceTest.php
+++ b/app/code/Magento/Integration/Test/Unit/Model/CustomerTokenServiceTest.php
@@ -32,6 +32,9 @@ class CustomerTokenServiceTest extends \PHPUnit\Framework\TestCase
/** @var \Magento\Integration\Model\Oauth\Token|\PHPUnit_Framework_MockObject_MockObject */
private $_tokenMock;
+ /** @var \Magento\Framework\Event\ManagerInterface|\PHPUnit_Framework_MockObject_MockObject */
+ protected $manager;
+
protected function setUp()
{
$this->_tokenFactoryMock = $this->getMockBuilder(\Magento\Integration\Model\Oauth\TokenFactory::class)
@@ -67,11 +70,14 @@ protected function setUp()
\Magento\Integration\Model\CredentialsValidator::class
)->disableOriginalConstructor()->getMock();
+ $this->manager = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
+
$this->_tokenService = new \Magento\Integration\Model\CustomerTokenService(
$this->_tokenFactoryMock,
$this->_accountManagementMock,
$this->_tokenModelCollectionFactoryMock,
- $this->validatorHelperMock
+ $this->validatorHelperMock,
+ $this->manager
);
}
diff --git a/app/code/Magento/Integration/etc/webapi_rest/events.xml b/app/code/Magento/Integration/etc/webapi_rest/events.xml
new file mode 100644
index 0000000000000..e978698734277
--- /dev/null
+++ b/app/code/Magento/Integration/etc/webapi_rest/events.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
diff --git a/app/code/Magento/Integration/etc/webapi_soap/events.xml b/app/code/Magento/Integration/etc/webapi_soap/events.xml
new file mode 100644
index 0000000000000..e978698734277
--- /dev/null
+++ b/app/code/Magento/Integration/etc/webapi_soap/events.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+