Skip to content

Commit d3a9093

Browse files
authored
Merge pull request #23 from AleksandrsKondratjevs/issue03486
issue-3864 - Remove plugin disabling and revoke token on each request
2 parents b1aa192 + 403db9c commit d3a9093

2 files changed

Lines changed: 28 additions & 25 deletions

File tree

src/Model/Context/AddUserInfoToContext.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Magento\Customer\Model\Session;
1919
use Magento\GraphQl\Model\Query\ContextParametersInterface;
2020
use Magento\CustomerGraphQl\Model\Context\AddUserInfoToContext as CoreAddUserInfoToContext;
21+
use Magento\Integration\Api\CustomerTokenServiceInterface;
22+
use Magento\Integration\Model\ResourceModel\Oauth\Token\CollectionFactory as TokenCollectionFactory;
2123

2224
/**
2325
* @inheritdoc
@@ -39,6 +41,16 @@ class AddUserInfoToContext extends CoreAddUserInfoToContext
3941
*/
4042
protected $customerRepository;
4143

44+
/**
45+
* @var CustomerTokenServiceInterface
46+
*/
47+
protected $customerTokenService;
48+
49+
/**
50+
* @var TokenCollectionFactory
51+
*/
52+
protected $tokenModelCollectionFactory;
53+
4254
/**
4355
* @param UserContextInterface $userContext
4456
* @param Session $session
@@ -47,7 +59,9 @@ class AddUserInfoToContext extends CoreAddUserInfoToContext
4759
public function __construct(
4860
UserContextInterface $userContext,
4961
Session $session,
50-
CustomerRepository $customerRepository
62+
CustomerRepository $customerRepository,
63+
CustomerTokenServiceInterface $customerTokenService,
64+
TokenCollectionFactory $tokenModelCollectionFactory
5165
) {
5266
parent::__construct(
5367
$userContext,
@@ -58,6 +72,8 @@ public function __construct(
5872
$this->userContext = $userContext;
5973
$this->session = $session;
6074
$this->customerRepository = $customerRepository;
75+
$this->customerTokenService = $customerTokenService;
76+
$this->tokenModelCollectionFactory = $tokenModelCollectionFactory;
6177
}
6278

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

87-
/*
88-
* TODO: implement support for sessions
89-
*
90-
if ($isCustomer) {
91-
$customer = $this->customerRepository->getById($currentUserId);
92-
$this->session->setCustomerData($customer);
93-
$this->session->setCustomerGroupId($customer->getGroupId());
103+
if ($isCustomer) {
104+
$customer = $this->customerRepository->getById($currentUserId);
105+
$this->session->setCustomerData($customer);
106+
$this->session->setCustomerGroupId($customer->getGroupId());
107+
108+
// Added next lines to revoke token on each request if user token is still exist
109+
$tokenCollection = $this->tokenModelCollectionFactory->create()->addFilterByCustomerId($currentUserId);
110+
111+
if ($tokenCollection->getSize() > 0) {
112+
$this->customerTokenService->revokeCustomerAccessToken($currentUserId);
94113
}
95-
*/
114+
}
96115

97116
return $contextParameters;
98117
}

src/etc/graphql/di.xml

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)