I am writing after plugin on create account method, to change the API response with. I have to call
createCustomerAccessToken($username, $password)
function, which has two parameters. What I am doing is i take the username from createAccount
method and pass it to createCustomerAccessToken
function.I can easily get the $username
value how i can get the password parameter value?
<?php
namespace Mlameh\Store\Plugin;
class AddAccessToken
{
/**
* @var \Magento\Customer\Api\Data\CustomerExtensionFactory
*/
private $customerExtensionFactory;
/**
* @var \Magento\Integration\Model\Oauth\TokenFactory
*/
private $tokenModelFactory;
/**
* @var \Magento\Integration\Model\CustomerTokenService
*/
private $customerTokenService;
private $token;
public function __construct(
\Magento\Integration\Model\CustomerTokenService $customerTokenService
) {
$this->customerTokenService = $customerTokenService;
}
/**
* Add Login token to customer
*
* @param \Magento\Customer\Api\AccountManagementInterface $subject ,
* @param \Magento\Customer\Api\Data\CustomerInterface $customer
* @return \Magento\Customer\Api\Data\CustomerInterface
* @throws \Magento\Framework\Exception\AuthenticationException
*/
public function afterCreateAccount(
\Magento\Customer\Api\AccountManagementInterface $subject,
\Magento\Customer\Api\Data\CustomerInterface $customer
) {
//$password =
$token['token'] = $this->customerTokenService->createCustomerAccessToken(
$customer->getEmail()
);
return $customer;
}
}