Skip to content

Commit 2f92720

Browse files
committed
MC-41363: Customer API improvement
1 parent e3f0d94 commit 2f92720

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

app/code/Magento/Customer/Model/Plugin/UpdateCustomer.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
use Magento\Framework\Webapi\Rest\Request as RestRequest;
1212
use Magento\Customer\Api\Data\CustomerInterface;
1313
use Magento\Customer\Api\CustomerRepositoryInterface;
14-
use Magento\Customer\Model\Session;
1514
use Magento\Framework\App\ObjectManager;
15+
use Magento\Integration\Model\Oauth\Token;
1616

1717
/**
1818
* Update customer by id from request param
@@ -25,21 +25,21 @@ class UpdateCustomer
2525
private $request;
2626

2727
/**
28-
* @var Session
28+
* @var Token
2929
*/
30-
private $session;
30+
private $token;
3131

3232
/**
3333
* @param RestRequest $request
34-
* @param Session|null $session
34+
* @param Token|null $token
3535
*/
3636
public function __construct(
3737
RestRequest $request,
38-
Session $session = null
38+
Token $token = null
3939
) {
4040
$this->request = $request;
41-
$this->session = $session ?: ObjectManager::getInstance()
42-
->get(Session::class);
41+
$this->token = $token ?: ObjectManager::getInstance()
42+
->get(Token::class);
4343
}
4444

4545
/**
@@ -56,9 +56,17 @@ public function beforeSave(
5656
?string $passwordHash = null
5757
): array {
5858
$customerId = $this->request->getParam('customerId');
59-
60-
if ($customerId && $customerId === $this->session->getData('customer_id')) {
61-
$customer = $this->getUpdatedCustomer($customerRepository->getById($customerId), $customer);
59+
$cookie = $this->request->getHeader('cookie');
60+
$headerToken = $this->request->getHeader('Authorization');
61+
if ($customerId && !str_contains($cookie, 'PHPSESSID')) {
62+
if (str_contains($headerToken, 'Bearer')) {
63+
$token = "Bearer " . $this->token->loadByCustomerId($customerId)->getData('token');
64+
if ($headerToken === $token) {
65+
$customer = $this->getUpdatedCustomer($customerRepository->getById($customerId), $customer);
66+
}
67+
} else {
68+
$customer = $this->getUpdatedCustomer($customerRepository->getById($customerId), $customer);
69+
}
6270
}
6371

6472
return [$customer, $passwordHash];

0 commit comments

Comments
 (0)