Skip to content

Commit

Permalink
Merge pull request #23 from AleksandrsKondratjevs/issue03486
Browse files Browse the repository at this point in the history
issue-3864 - Remove plugin disabling and revoke token on each request
  • Loading branch information
carinadues authored Oct 28, 2021
2 parents b1aa192 + 403db9c commit d3a9093
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 25 deletions.
37 changes: 28 additions & 9 deletions src/Model/Context/AddUserInfoToContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Magento\Customer\Model\Session;
use Magento\GraphQl\Model\Query\ContextParametersInterface;
use Magento\CustomerGraphQl\Model\Context\AddUserInfoToContext as CoreAddUserInfoToContext;
use Magento\Integration\Api\CustomerTokenServiceInterface;
use Magento\Integration\Model\ResourceModel\Oauth\Token\CollectionFactory as TokenCollectionFactory;

/**
* @inheritdoc
Expand All @@ -39,6 +41,16 @@ class AddUserInfoToContext extends CoreAddUserInfoToContext
*/
protected $customerRepository;

/**
* @var CustomerTokenServiceInterface
*/
protected $customerTokenService;

/**
* @var TokenCollectionFactory
*/
protected $tokenModelCollectionFactory;

/**
* @param UserContextInterface $userContext
* @param Session $session
Expand All @@ -47,7 +59,9 @@ class AddUserInfoToContext extends CoreAddUserInfoToContext
public function __construct(
UserContextInterface $userContext,
Session $session,
CustomerRepository $customerRepository
CustomerRepository $customerRepository,
CustomerTokenServiceInterface $customerTokenService,
TokenCollectionFactory $tokenModelCollectionFactory
) {
parent::__construct(
$userContext,
Expand All @@ -58,6 +72,8 @@ public function __construct(
$this->userContext = $userContext;
$this->session = $session;
$this->customerRepository = $customerRepository;
$this->customerTokenService = $customerTokenService;
$this->tokenModelCollectionFactory = $tokenModelCollectionFactory;
}

/**
Expand All @@ -84,15 +100,18 @@ public function execute(ContextParametersInterface $contextParameters): ContextP
$isCustomer = $this->isCustomer($currentUserId, $currentUserType);
$contextParameters->addExtensionAttribute('is_customer', $isCustomer);

/*
* TODO: implement support for sessions
*
if ($isCustomer) {
$customer = $this->customerRepository->getById($currentUserId);
$this->session->setCustomerData($customer);
$this->session->setCustomerGroupId($customer->getGroupId());
if ($isCustomer) {
$customer = $this->customerRepository->getById($currentUserId);
$this->session->setCustomerData($customer);
$this->session->setCustomerGroupId($customer->getGroupId());

// Added next lines to revoke token on each request if user token is still exist
$tokenCollection = $this->tokenModelCollectionFactory->create()->addFilterByCustomerId($currentUserId);

if ($tokenCollection->getSize() > 0) {
$this->customerTokenService->revokeCustomerAccessToken($currentUserId);
}
*/
}

return $contextParameters;
}
Expand Down
16 changes: 0 additions & 16 deletions src/etc/graphql/di.xml

This file was deleted.

0 comments on commit d3a9093

Please sign in to comment.