Skip to content

Commit 58dfc61

Browse files
author
magento packaging service
committed
Magento Release 2.4.5-p3
1 parent 750f3c8 commit 58dfc61

File tree

363 files changed

+21414
-17531
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

363 files changed

+21414
-17531
lines changed

app/code/Magento/AdminAdobeIms/Controller/Adminhtml/OAuth/ImsCallback.php

+31
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@
2121
use Magento\Backend\Model\View\Result\Redirect;
2222
use Magento\Framework\App\Action\HttpGetActionInterface;
2323
use Magento\Framework\Exception\AuthenticationException;
24+
use Magento\Framework\App\ActionInterface;
25+
use Magento\Framework\App\RequestInterface;
26+
use Magento\Framework\App\ResponseInterface;
2427

28+
/**
29+
* Class ImsCallback is responsible to get the Access Token, User Profile,
30+
* check if the assigned organization is valid, And Check if user exists and then do the login
31+
*
32+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
33+
*/
2534
class ImsCallback extends Auth implements HttpGetActionInterface
2635
{
2736
public const ACTION_NAME = 'imscallback';
@@ -75,6 +84,28 @@ public function __construct(
7584
$this->logger = $logger;
7685
}
7786

87+
/**
88+
* Validate IMS state is valid
89+
*
90+
* @param RequestInterface $request
91+
* @return ResponseInterface
92+
*/
93+
public function dispatch(RequestInterface $request)
94+
{
95+
$request->setParam('form_key', $request->getParam('state', null));
96+
if (!$this->_formKeyValidator->validate($request)) {
97+
$this->logger->critical(__('Invalid state returned in callback from IMS.'));
98+
$this->imsErrorMessage(
99+
'Error signing in',
100+
'Something went wrong and we could not sign you in. ' .
101+
'Please try again or contact your administrator.'
102+
);
103+
$this->_actionFlag->set('', ActionInterface::FLAG_NO_DISPATCH, true);
104+
return $this->_redirect($this->_helper->getHomePageUrl());
105+
}
106+
return parent::dispatch($request);
107+
}
108+
78109
/**
79110
* Execute AdobeIMS callback
80111
*

app/code/Magento/AdminAdobeIms/Controller/Adminhtml/OAuth/ImsReauthCallback.php

+18
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use Magento\Framework\Controller\Result\Raw;
2222
use Magento\Framework\Controller\ResultFactory;
2323
use Magento\Framework\Exception\AuthenticationException;
24+
use Magento\Framework\App\RequestInterface;
25+
use Magento\Framework\Exception\NotFoundException;
2426

2527
class ImsReauthCallback extends Auth implements HttpGetActionInterface
2628
{
@@ -111,6 +113,7 @@ public function execute(): ResultInterface
111113
}
112114

113115
try {
116+
$this->validateStateKey($this->getRequest());
114117
$code = $this->getRequest()->getParam('code');
115118

116119
if ($code === null) {
@@ -149,4 +152,19 @@ public function execute(): ResultInterface
149152

150153
return $resultRaw;
151154
}
155+
156+
/**
157+
* Validate IMS state is valid
158+
*
159+
* @param RequestInterface $request
160+
* @return void
161+
* @throws NotFoundException
162+
*/
163+
private function validateStateKey(RequestInterface $request): void
164+
{
165+
$request->setParam('form_key', $request->getParam('state', null));
166+
if (!$this->_formKeyValidator->validate($request)) {
167+
throw new NotFoundException(__('Invalid state returned from IMS'));
168+
}
169+
}
152170
}

app/code/Magento/AdminAdobeIms/Model/ImsConnection.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,12 @@ public function validateToken(?string $token, string $tokenType = 'access_token'
167167
$curl->addHeader('cache-control', 'no-cache');
168168

169169
$curl->post(
170-
$this->adminImsConfig->getValidateTokenUrl($token, $tokenType),
171-
[]
170+
$this->adminImsConfig->getValidateTokenUrl(),
171+
[
172+
'token' => $token,
173+
'type' => $tokenType,
174+
'client_id' => $this->adminImsConfig->getApiKey()
175+
]
172176
);
173177

174178
if ($curl->getBody() === '') {

app/code/Magento/AdminAdobeIms/Model/LogOut.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,12 @@ private function externalLogOut(string $accessToken): void
112112
$curl->addHeader('cache-control', 'no-cache');
113113

114114
$curl->post(
115-
$this->adminImsConfig->getBackendLogoutUrl($accessToken),
116-
[]
115+
$this->adminImsConfig->getBackendLogoutUrl(),
116+
[
117+
'access_token' => $accessToken,
118+
'client_secret' => $this->adminImsConfig->getPrivateKey(),
119+
'client_id' => $this->adminImsConfig->getApiKey()
120+
]
117121
);
118122

119123
if ($curl->getStatus() !== self::HTTP_OK || ($this->checkUserProfile($accessToken))) {

app/code/Magento/AdminAdobeIms/Service/ImsConfig.php

+18-18
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Magento\Framework\Encryption\EncryptorInterface;
1919
use Magento\Framework\Exception\LocalizedException;
2020
use Magento\Framework\UrlInterface;
21+
use Magento\Framework\Data\Form\FormKey;
2122

2223
class ImsConfig extends Config
2324
{
@@ -58,25 +59,33 @@ class ImsConfig extends Config
5859
*/
5960
private BackendUrlInterface $backendUrl;
6061

62+
/**
63+
* @var FormKey
64+
*/
65+
private FormKey $formKey;
66+
6167
/**
6268
* @param ScopeConfigInterface $scopeConfig
6369
* @param UrlInterface $url
6470
* @param WriterInterface $writer
6571
* @param EncryptorInterface $encryptor
6672
* @param BackendUrlInterface $backendUrl
73+
* @param FormKey $formKey
6774
*/
6875
public function __construct(
6976
ScopeConfigInterface $scopeConfig,
7077
UrlInterface $url,
7178
WriterInterface $writer,
7279
EncryptorInterface $encryptor,
73-
BackendUrlInterface $backendUrl
80+
BackendUrlInterface $backendUrl,
81+
FormKey $formKey
7482
) {
7583
parent::__construct($scopeConfig, $url);
7684
$this->writer = $writer;
7785
$this->encryptor = $encryptor;
7886
$this->scopeConfig = $scopeConfig;
7987
$this->backendUrl = $backendUrl;
88+
$this->formKey = $formKey;
8089
}
8190

8291
/**
@@ -180,17 +189,11 @@ public function getProfileUrl(): string
180189
/**
181190
* Get Token validation url
182191
*
183-
* @param string $code
184-
* @param string $tokenType
185192
* @return string
186193
*/
187-
public function getValidateTokenUrl(string $code, string $tokenType): string
194+
public function getValidateTokenUrl(): string
188195
{
189-
return str_replace(
190-
['#{token}', '#{client_id}', '#{token_type}'],
191-
[$code, $this->getApiKey(), $tokenType],
192-
$this->scopeConfig->getValue(self::XML_PATH_VALIDATE_TOKEN_URL)
193-
);
196+
return $this->scopeConfig->getValue(self::XML_PATH_VALIDATE_TOKEN_URL);
194197
}
195198

196199
/**
@@ -253,11 +256,12 @@ public function getAdminAdobeImsAuthUrl(?string $clientId): string
253256
}
254257

255258
return str_replace(
256-
['#{client_id}', '#{redirect_uri}', '#{scope}', '#{locale}'],
259+
['#{client_id}', '#{redirect_uri}', '#{scope}', '#{state}', '#{locale}'],
257260
[
258261
$clientId,
259262
$this->getAdminAdobeImsCallBackUrl(),
260263
$this->getScopes(),
264+
$this->formKey->getFormKey(),
261265
$this->getLocale()
262266
],
263267
$this->scopeConfig->getValue(self::XML_PATH_ADMIN_AUTH_URL_PATTERN)
@@ -272,11 +276,12 @@ public function getAdminAdobeImsAuthUrl(?string $clientId): string
272276
public function getAdminAdobeImsReAuthUrl(): string
273277
{
274278
return str_replace(
275-
['#{client_id}', '#{redirect_uri}', '#{scope}', '#{locale}'],
279+
['#{client_id}', '#{redirect_uri}', '#{scope}', '#{state}', '#{locale}'],
276280
[
277281
$this->getApiKey(),
278282
$this->getAdminAdobeImsReAuthCallBackUrl(),
279283
$this->getScopes(),
284+
$this->formKey->getFormKey(),
280285
$this->getLocale()
281286
],
282287
$this->scopeConfig->getValue(self::XML_PATH_ADMIN_REAUTH_URL_PATTERN)
@@ -345,16 +350,11 @@ private function getLocale(): string
345350
/**
346351
* Get BackendLogout URL
347352
*
348-
* @param string $accessToken
349353
* @return string
350354
*/
351-
public function getBackendLogoutUrl(string $accessToken) : string
355+
public function getBackendLogoutUrl() : string
352356
{
353-
return str_replace(
354-
['#{access_token}', '#{client_secret}', '#{client_id}'],
355-
[$accessToken, $this->getPrivateKey(), $this->getApiKey()],
356-
$this->scopeConfig->getValue(self::XML_PATH_ADMIN_LOGOUT_URL)
357-
);
357+
return $this->scopeConfig->getValue(self::XML_PATH_ADMIN_LOGOUT_URL);
358358
}
359359

360360
/**

app/code/Magento/AdminAdobeIms/Service/ImsOrganizationService.php

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public function checkOrganizationMembership(string $access_token): void
7575
__('User is not a member of configured Adobe Organization.')
7676
);
7777
}
78-
7978
} catch (\Exception $exception) {
8079
throw new AdobeImsOrganizationAuthorizationException(
8180
__('Organization Membership check can\'t be performed')

0 commit comments

Comments
 (0)