Skip to content

Commit 2ee6146

Browse files
authored
Merge branch '2.4-develop' into 2.4-develop
2 parents fe2fb01 + 9c42b97 commit 2ee6146

File tree

406 files changed

+13619
-10080
lines changed

Some content is hidden

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

406 files changed

+13619
-10080
lines changed

.github/ISSUE_TEMPLATE/developer-experience-issue.md

Lines changed: 0 additions & 29 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Developer experience issue
2+
description: Issues related to customization, extensibility, modularity
3+
labels: ['Triage: Dev.Experience']
4+
body:
5+
- type: markdown
6+
attributes:
7+
value: |
8+
Please read [our guidelines](https://developer.adobe.com/commerce/contributor/guides/code-contributions/#report-an-issue) before submitting the issue.
9+
- type: textarea
10+
attributes:
11+
label: Summary
12+
description: |
13+
Describe the issue you are experiencing.
14+
Include general information, error messages, environments, and so on.
15+
validations:
16+
required: true
17+
- type: textarea
18+
attributes:
19+
label: Examples
20+
description: |
21+
Provide code examples or a patch with a test (recommended) to clearly indicate the problem.
22+
validations:
23+
required: true
24+
- type: textarea
25+
attributes:
26+
label: Proposed solution
27+
description: |
28+
Suggest your potential solutions for this issue.
29+
- type: textarea
30+
attributes:
31+
label: Release note
32+
description: |
33+
Help us to provide meaningful release notes to the community.
34+
- type: checkboxes
35+
attributes:
36+
label: Triage and priority
37+
description: |
38+
Provide [Severity](https://developer.adobe.com/commerce/contributor/guides/code-contributions/#community-backlog-priority) assessment for the Issue as a Reporter.
39+
This information helps us during the Confirmation and Issue triage processes.
40+
options:
41+
- label: 'Severity: **S0** _- Affects critical data or functionality and leaves users without workaround._'
42+
- label: 'Severity: **S1** _- Affects critical data or functionality and forces users to employ a workaround._'
43+
- label: 'Severity: **S2** _- Affects non-critical data or functionality and forces users to employ a workaround._'
44+
- label: 'Severity: **S3** _- Affects non-critical data or functionality and does not force users to employ a workaround._'
45+
- label: 'Severity: **S4** _- Affects aesthetics, professional look and feel, “quality” or “usability”._'

.github/ISSUE_TEMPLATE/feature_request.md

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Feature request
2+
description: Report to https://github.com/magento/community-features
3+
labels: ['feature request']
4+
body:
5+
- type: markdown
6+
attributes:
7+
value: |
8+
Important: This repository is intended only for Magento 2 Technical Issues.
9+
Enter Feature Requests at https://github.com/magento/community-features.
10+
Project stakeholders monitor and manage requests.
11+
Feature requests entered using this form may be moved to the forum.
12+
- type: textarea
13+
attributes:
14+
label: Description
15+
description: |
16+
Describe the feature you would like to add.
17+
validations:
18+
required: true
19+
- type: textarea
20+
attributes:
21+
label: Expected behavior
22+
description: |
23+
What is the expected behavior of this feature?
24+
How is it going to work?
25+
validations:
26+
required: true
27+
- type: textarea
28+
attributes:
29+
label: Benefits
30+
description: |
31+
How do you think this feature would improve Magento?
32+
- type: textarea
33+
attributes:
34+
label: Additional information
35+
description: |
36+
What other information can you provide about the desired feature?
37+
- type: textarea
38+
attributes:
39+
label: Release note
40+
description: |
41+
Help us to provide meaningful release notes to the community.

app/code/Magento/AdminAdobeIms/Model/Authorization/AdobeImsAdminTokenUserService.php

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,24 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
declare(strict_types=1);
87

98
namespace Magento\AdminAdobeIms\Model\Authorization;
109

10+
use Magento\AdminAdobeIms\Api\SaveImsUserInterface;
1111
use Magento\AdminAdobeIms\Exception\AdobeImsAuthorizationException;
1212
use Magento\AdminAdobeIms\Service\AdminLoginProcessService;
1313
use Magento\AdminAdobeIms\Service\AdminReauthProcessService;
1414
use Magento\AdminAdobeIms\Service\ImsConfig;
1515
use Magento\AdobeIms\Exception\AdobeImsOrganizationAuthorizationException;
16+
use Magento\AdobeImsApi\Api\Data\TokenResponseInterface;
17+
use Magento\AdobeImsApi\Api\Data\TokenResponseInterfaceFactory;
1618
use Magento\AdobeImsApi\Api\GetProfileInterface;
1719
use Magento\AdobeImsApi\Api\GetTokenInterface;
1820
use Magento\AdobeImsApi\Api\OrganizationMembershipInterface;
1921
use Magento\Framework\App\RequestInterface;
2022
use Magento\Framework\Exception\AuthenticationException;
21-
use Magento\AdminAdobeIms\Api\SaveImsUserInterface;
23+
use Magento\Framework\Exception\AuthorizationException;
2224

2325
/**
2426
* Adobe IMS Auth Model for getting Admin Token
@@ -28,6 +30,7 @@
2830
class AdobeImsAdminTokenUserService
2931
{
3032
private const ADOBE_IMS_MODULE_NAME = 'adobe_ims_auth';
33+
private const AUTHORIZATION_METHOD_HEADER_BEARER = 'bearer';
3134

3235
/**
3336
* @var ImsConfig
@@ -64,6 +67,11 @@ class AdobeImsAdminTokenUserService
6467
*/
6568
private RequestInterface $request;
6669

70+
/**
71+
* @var TokenResponseInterfaceFactory
72+
*/
73+
private TokenResponseInterfaceFactory $tokenResponseFactory;
74+
6775
/**
6876
* @var SaveImsUserInterface
6977
*/
@@ -77,6 +85,7 @@ class AdobeImsAdminTokenUserService
7785
* @param RequestInterface $request
7886
* @param GetTokenInterface $token
7987
* @param GetProfileInterface $profile
88+
* @param TokenResponseInterfaceFactory $tokenResponseFactory
8089
* @param SaveImsUserInterface $saveImsUser
8190
*/
8291
public function __construct(
@@ -87,6 +96,7 @@ public function __construct(
8796
RequestInterface $request,
8897
GetTokenInterface $token,
8998
GetProfileInterface $profile,
99+
TokenResponseInterfaceFactory $tokenResponseFactory,
90100
SaveImsUserInterface $saveImsUser
91101
) {
92102
$this->adminImsConfig = $adminImsConfig;
@@ -96,6 +106,7 @@ public function __construct(
96106
$this->request = $request;
97107
$this->token = $token;
98108
$this->profile = $profile;
109+
$this->tokenResponseFactory = $tokenResponseFactory;
99110
$this->saveImsUser = $saveImsUser;
100111
}
101112

@@ -107,33 +118,23 @@ public function __construct(
107118
* @throws AdobeImsAuthorizationException
108119
* @throws AdobeImsOrganizationAuthorizationException
109120
* @throws AuthenticationException
121+
* @throws AuthorizationException
110122
*/
111123
public function processLoginRequest(bool $isReauthorize = false): void
112124
{
113-
if ($this->adminImsConfig->enabled() && $this->request->getParam('code')
125+
if ($this->adminImsConfig->enabled()
114126
&& $this->request->getModuleName() === self::ADOBE_IMS_MODULE_NAME) {
115127
try {
116-
$code = $this->request->getParam('code');
117-
118-
//get token from response
119-
$tokenResponse = $this->token->getTokenResponse($code);
120-
$accessToken = $tokenResponse->getAccessToken();
121-
122-
//get profile info to check email
123-
$profile = $this->profile->getProfile($accessToken);
124-
if (empty($profile['email'])) {
125-
throw new AuthenticationException(__('An authentication error occurred. Verify and try again.'));
126-
}
127-
128-
//check membership in organization
129-
$this->organizationMembership->checkOrganizationMembership($accessToken);
130-
131-
if ($isReauthorize) {
132-
$this->adminReauthProcessService->execute($tokenResponse);
128+
if ($this->request->getHeader('Authorization')) {
129+
$tokenResponse = $this->getRequestedToken();
130+
} elseif ($this->request->getParam('code')) {
131+
$code = $this->request->getParam('code');
132+
$tokenResponse = $this->token->getTokenResponse($code);
133133
} else {
134-
$this->saveImsUser->save($profile);
135-
$this->adminLoginProcessService->execute($tokenResponse, $profile);
134+
throw new AuthenticationException(__('Unable to get Access Token. Please try again.'));
136135
}
136+
137+
$this->getLoggedIn($isReauthorize, $tokenResponse);
137138
} catch (AdobeImsAuthorizationException $e) {
138139
throw new AdobeImsAuthorizationException(
139140
__('You don\'t have access to this Commerce instance')
@@ -147,4 +148,58 @@ public function processLoginRequest(bool $isReauthorize = false): void
147148
throw new AuthenticationException(__('An authentication error occurred. Verify and try again.'));
148149
}
149150
}
151+
152+
/**
153+
* Get requested token using Authorization header
154+
*
155+
* @return TokenResponseInterface
156+
* @throws AuthenticationException
157+
*/
158+
private function getRequestedToken(): TokenResponseInterface
159+
{
160+
$authorizationHeaderValue = $this->request->getHeader('Authorization');
161+
if (!$authorizationHeaderValue) {
162+
throw new AuthenticationException(__('An authentication error occurred. Verify and try again.'));
163+
}
164+
165+
$headerPieces = explode(" ", $authorizationHeaderValue);
166+
if (count($headerPieces) !== 2) {
167+
throw new AuthenticationException(__('An authentication error occurred. Verify and try again.'));
168+
}
169+
170+
$tokenType = strtolower($headerPieces[0]);
171+
if ($tokenType !== self::AUTHORIZATION_METHOD_HEADER_BEARER) {
172+
throw new AuthenticationException(__('An authentication error occurred. Verify and try again.'));
173+
}
174+
175+
$tokenResponse['access_token'] = $headerPieces[1];
176+
return $this->tokenResponseFactory->create(['data' => $tokenResponse]);
177+
}
178+
179+
/**
180+
* Responsible for logging in to Admin Panel
181+
*
182+
* @param bool $isReauthorize
183+
* @param TokenResponseInterface $tokenResponse
184+
* @return void
185+
* @throws AdobeImsAuthorizationException
186+
* @throws AuthenticationException
187+
* @throws AuthorizationException
188+
*/
189+
private function getLoggedIn(bool $isReauthorize, TokenResponseInterface $tokenResponse): void
190+
{
191+
$profile = $this->profile->getProfile($tokenResponse->getAccessToken());
192+
if (empty($profile['email'])) {
193+
throw new AuthenticationException(__('An authentication error occurred. Verify and try again.'));
194+
}
195+
196+
$this->organizationMembership->checkOrganizationMembership($tokenResponse->getAccessToken());
197+
198+
if ($isReauthorize) {
199+
$this->adminReauthProcessService->execute($tokenResponse);
200+
} else {
201+
$this->saveImsUser->save($profile);
202+
$this->adminLoginProcessService->execute($tokenResponse, $profile);
203+
}
204+
}
150205
}

0 commit comments

Comments
 (0)