Skip to content

Commit 23ba532

Browse files
CABI-365::AdobeAdminIms to AdobeIms code migration
1 parent c3ad511 commit 23ba532

38 files changed

+1352
-501
lines changed

app/code/Magento/AdminAdobeIms/Console/Command/AdminAdobeImsEnableCommand.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
declare(strict_types=1);
88

99
namespace Magento\AdminAdobeIms\Console\Command;
10-
11-
use Magento\AdminAdobeIms\Model\ImsConnection;
12-
use Magento\AdminAdobeIms\Service\UpdateTokensService;
1310
use Magento\AdminAdobeIms\Service\ImsCommandOptionService;
1411
use Magento\AdminAdobeIms\Service\ImsConfig;
12+
use Magento\AdminAdobeIms\Service\UpdateTokensService;
13+
use Magento\AdobeImsApi\Api\GetAuthorizationUrlInterface;
1514
use Magento\Framework\App\Cache\Type\Config;
1615
use Magento\Framework\App\Cache\TypeListInterface;
1716
use Magento\Framework\Console\Cli;
@@ -53,11 +52,6 @@ class AdminAdobeImsEnableCommand extends Command
5352
*/
5453
private ImsConfig $adminImsConfig;
5554

56-
/**
57-
* @var ImsConnection
58-
*/
59-
private ImsConnection $adminImsConnection;
60-
6155
/**
6256
* @var ImsCommandOptionService
6357
*/
@@ -73,26 +67,31 @@ class AdminAdobeImsEnableCommand extends Command
7367
*/
7468
private UpdateTokensService $updateTokensService;
7569

70+
/**
71+
* @var GetAuthorizationUrlInterface
72+
*/
73+
private GetAuthorizationUrlInterface $authorizationUrl;
74+
7675
/**
7776
* @param ImsConfig $adminImsConfig
78-
* @param ImsConnection $adminImsConnection
7977
* @param ImsCommandOptionService $imsCommandOptionService
8078
* @param TypeListInterface $cacheTypeList
8179
* @param UpdateTokensService $updateTokensService
80+
* @param GetAuthorizationUrlInterface $authorizationUrl
8281
*/
8382
public function __construct(
8483
ImsConfig $adminImsConfig,
85-
ImsConnection $adminImsConnection,
8684
ImsCommandOptionService $imsCommandOptionService,
8785
TypeListInterface $cacheTypeList,
88-
UpdateTokensService $updateTokensService
86+
UpdateTokensService $updateTokensService,
87+
GetAuthorizationUrlInterface $authorizationUrl
8988
) {
9089
parent::__construct();
9190
$this->adminImsConfig = $adminImsConfig;
92-
$this->adminImsConnection = $adminImsConnection;
9391
$this->imsCommandOptionService = $imsCommandOptionService;
9492
$this->cacheTypeList = $cacheTypeList;
9593
$this->updateTokensService = $updateTokensService;
94+
$this->authorizationUrl = $authorizationUrl;
9695

9796
$this->setName('admin:adobe-ims:enable')
9897
->setDescription('Enable Adobe IMS Module.')
@@ -199,7 +198,7 @@ private function enableModule(
199198
string $organizationId,
200199
bool $isTwoFactorAuthEnabled
201200
): bool {
202-
$testAuth = $this->adminImsConnection->testAuth($clientId);
201+
$testAuth = $this->authorizationUrl->testAuth($clientId);
203202
if ($testAuth) {
204203
$this->adminImsConfig->enableModule($clientId, $clientSecret, $organizationId, $isTwoFactorAuthEnabled);
205204
$this->cacheTypeList->cleanType(Config::TYPE_IDENTIFIER);

app/code/Magento/AdminAdobeIms/Console/Command/AdminAdobeImsInfoCommand.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
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\Console\Command;
109

11-
use Magento\AdminAdobeIms\Model\ImsConnection;
1210
use Magento\AdminAdobeIms\Service\ImsConfig;
11+
use Magento\AdobeImsApi\Api\GetAuthorizationUrlInterface;
1312
use Magento\Framework\Console\Cli;
1413
use Symfony\Component\Console\Command\Command;
1514
use Symfony\Component\Console\Input\InputInterface;
@@ -41,21 +40,21 @@ class AdminAdobeImsInfoCommand extends Command
4140
private ImsConfig $adminImsConfig;
4241

4342
/**
44-
* @var ImsConnection
43+
* @var GetAuthorizationUrlInterface
4544
*/
46-
private ImsConnection $adminImsConnection;
45+
private GetAuthorizationUrlInterface $authorizationUrl;
4746

4847
/**
4948
* @param ImsConfig $adminImsConfig
50-
* @param ImsConnection $adminImsConnection
49+
* @param GetAuthorizationUrlInterface $authorizationUrl
5150
*/
5251
public function __construct(
5352
ImsConfig $adminImsConfig,
54-
ImsConnection $adminImsConnection
53+
GetAuthorizationUrlInterface $authorizationUrl
5554
) {
5655
parent::__construct();
5756
$this->adminImsConfig = $adminImsConfig;
58-
$this->adminImsConnection = $adminImsConnection;
57+
$this->authorizationUrl = $authorizationUrl;
5958

6059
$this->setName('admin:adobe-ims:info')
6160
->setDescription('Information of Adobe IMS Module configuration');
@@ -69,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output): ?int
6968
try {
7069
if ($this->adminImsConfig->enabled()) {
7170
$clientId = $this->adminImsConfig->getApiKey();
72-
if ($this->adminImsConnection->testAuth($clientId)) {
71+
if ($this->authorizationUrl->testAuth($clientId)) {
7372
$clientSecret = $this->adminImsConfig->getPrivateKey() ? 'configured' : 'not configured';
7473
$output->writeln(self::CLIENT_ID_NAME . ': ' . $clientId);
7574
$output->writeln(self::ORGANIZATION_ID_NAME . ': ' . $this->adminImsConfig->getOrganizationId());

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

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
namespace Magento\AdminAdobeIms\Controller\Adminhtml\OAuth;
1010

1111
use Exception;
12-
use Magento\AdminAdobeIms\Exception\AdobeImsOrganizationAuthorizationException;
1312
use Magento\AdminAdobeIms\Exception\AdobeImsAuthorizationException;
13+
use Magento\AdminAdobeIms\Exception\AdobeImsOrganizationAuthorizationException;
1414
use Magento\AdminAdobeIms\Logger\AdminAdobeImsLogger;
1515
use Magento\AdminAdobeIms\Service\AdminLoginProcessService;
1616
use Magento\AdminAdobeIms\Service\ImsConfig;
17-
use Magento\AdminAdobeIms\Service\ImsOrganizationService;
17+
use Magento\AdobeImsApi\Api\GetOrganizationsInterface;
18+
use Magento\AdobeImsApi\Api\GetProfileInterface;
19+
use Magento\AdobeImsApi\Api\GetTokenInterface;
1820
use Magento\Backend\App\Action\Context;
19-
use Magento\AdminAdobeIms\Model\ImsConnection;
2021
use Magento\Backend\Controller\Adminhtml\Auth;
2122
use Magento\Backend\Model\View\Result\Redirect;
2223
use Magento\Framework\App\Action\HttpGetActionInterface;
@@ -26,20 +27,15 @@ class ImsCallback extends Auth implements HttpGetActionInterface
2627
{
2728
public const ACTION_NAME = 'imscallback';
2829

29-
/**
30-
* @var ImsConnection
31-
*/
32-
private ImsConnection $adminImsConnection;
33-
3430
/**
3531
* @var ImsConfig
3632
*/
3733
private ImsConfig $adminImsConfig;
3834

3935
/**
40-
* @var ImsOrganizationService
36+
* @var GetOrganizationsInterface
4137
*/
42-
private ImsOrganizationService $adminOrganizationService;
38+
private GetOrganizationsInterface $organizations;
4339

4440
/**
4541
* @var AdminLoginProcessService
@@ -51,28 +47,41 @@ class ImsCallback extends Auth implements HttpGetActionInterface
5147
*/
5248
private AdminAdobeImsLogger $logger;
5349

50+
/**
51+
* @var GetTokenInterface
52+
*/
53+
private GetTokenInterface $token;
54+
55+
/**
56+
* @var GetProfileInterface
57+
*/
58+
private GetProfileInterface $profile;
59+
5460
/**
5561
* @param Context $context
56-
* @param ImsConnection $adminImsConnection
5762
* @param ImsConfig $adminImsConfig
58-
* @param ImsOrganizationService $adminOrganizationService
63+
* @param GetOrganizationsInterface $organizations
5964
* @param AdminLoginProcessService $adminLoginProcessService
6065
* @param AdminAdobeImsLogger $logger
66+
* @param GetTokenInterface $token
67+
* @param GetProfileInterface $profile
6168
*/
6269
public function __construct(
6370
Context $context,
64-
ImsConnection $adminImsConnection,
6571
ImsConfig $adminImsConfig,
66-
ImsOrganizationService $adminOrganizationService,
72+
GetOrganizationsInterface $organizations,
6773
AdminLoginProcessService $adminLoginProcessService,
68-
AdminAdobeImsLogger $logger
74+
AdminAdobeImsLogger $logger,
75+
GetTokenInterface $token,
76+
GetProfileInterface $profile
6977
) {
7078
parent::__construct($context);
71-
$this->adminImsConnection = $adminImsConnection;
7279
$this->adminImsConfig = $adminImsConfig;
73-
$this->adminOrganizationService = $adminOrganizationService;
80+
$this->organizations = $organizations;
7481
$this->adminLoginProcessService = $adminLoginProcessService;
7582
$this->logger = $logger;
83+
$this->token = $token;
84+
$this->profile = $profile;
7685
}
7786

7887
/**
@@ -99,17 +108,17 @@ public function execute(): Redirect
99108
}
100109

101110
//get token from response
102-
$tokenResponse = $this->adminImsConnection->getTokenResponse($code);
111+
$tokenResponse = $this->token->getTokenResponse($code);
103112
$accessToken = $tokenResponse->getAccessToken();
104113

105114
//get profile info to check email
106-
$profile = $this->adminImsConnection->getProfile($accessToken);
115+
$profile = $this->profile->getProfile($accessToken);
107116
if (empty($profile['email'])) {
108117
throw new AuthenticationException(__('An authentication error occurred. Verify and try again.'));
109118
}
110119

111120
//check membership in organization
112-
$this->adminOrganizationService->checkOrganizationMembership($accessToken);
121+
$this->organizations->checkOrganizationMembership($accessToken);
113122

114123
$this->adminLoginProcessService->execute($tokenResponse, $profile);
115124
} catch (AdobeImsAuthorizationException $e) {

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

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
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\Controller\Adminhtml\OAuth;
@@ -12,14 +11,15 @@
1211
use Magento\AdminAdobeIms\Logger\AdminAdobeImsLogger;
1312
use Magento\AdminAdobeIms\Service\AdminReauthProcessService;
1413
use Magento\AdminAdobeIms\Service\ImsConfig;
15-
use Magento\AdminAdobeIms\Service\ImsOrganizationService;
14+
use Magento\AdobeImsApi\Api\GetOrganizationsInterface;
15+
use Magento\AdobeImsApi\Api\GetProfileInterface;
1616
use Magento\Backend\App\Action\Context;
17-
use Magento\AdminAdobeIms\Model\ImsConnection;
1817
use Magento\Backend\Controller\Adminhtml\Auth;
19-
use Magento\Framework\Controller\ResultInterface;
2018
use Magento\Framework\App\Action\HttpGetActionInterface;
2119
use Magento\Framework\Controller\Result\Raw;
2220
use Magento\Framework\Controller\ResultFactory;
21+
use Magento\Framework\Controller\ResultInterface;
22+
use Magento\AdobeImsApi\Api\GetTokenInterface;
2323
use Magento\Framework\Exception\AuthenticationException;
2424

2525
class ImsReauthCallback extends Auth implements HttpGetActionInterface
@@ -37,20 +37,15 @@ class ImsReauthCallback extends Auth implements HttpGetActionInterface
3737
private const RESPONSE_SUCCESS_CODE = 'success';
3838
private const RESPONSE_ERROR_CODE = 'error';
3939

40-
/**
41-
* @var ImsConnection
42-
*/
43-
private ImsConnection $adminImsConnection;
44-
4540
/**
4641
* @var ImsConfig
4742
*/
4843
private ImsConfig $adminImsConfig;
4944

5045
/**
51-
* @var ImsOrganizationService
46+
* @var GetOrganizationsInterface
5247
*/
53-
private ImsOrganizationService $adminOrganizationService;
48+
private GetOrganizationsInterface $getOrganizations;
5449

5550
/**
5651
* @var AdminReauthProcessService
@@ -62,28 +57,41 @@ class ImsReauthCallback extends Auth implements HttpGetActionInterface
6257
*/
6358
private AdminAdobeImsLogger $logger;
6459

60+
/**
61+
* @var GetTokenInterface
62+
*/
63+
private GetTokenInterface $token;
64+
65+
/**
66+
* @var GetProfileInterface
67+
*/
68+
private GetProfileInterface $profile;
69+
6570
/**
6671
* @param Context $context
67-
* @param ImsConnection $adminImsConnection
72+
* @param GetProfileInterface $profile
6873
* @param ImsConfig $adminImsConfig
69-
* @param ImsOrganizationService $adminOrganizationService
74+
* @param GetOrganizationsInterface $getOrganizations
7075
* @param AdminReauthProcessService $adminReauthProcessService
7176
* @param AdminAdobeImsLogger $logger
77+
* @param GetTokenInterface $token
7278
*/
7379
public function __construct(
7480
Context $context,
75-
ImsConnection $adminImsConnection,
81+
GetProfileInterface $profile,
7682
ImsConfig $adminImsConfig,
77-
ImsOrganizationService $adminOrganizationService,
83+
GetOrganizationsInterface $getOrganizations,
7884
AdminReauthProcessService $adminReauthProcessService,
79-
AdminAdobeImsLogger $logger
85+
AdminAdobeImsLogger $logger,
86+
GetTokenInterface $token
8087
) {
8188
parent::__construct($context);
82-
$this->adminImsConnection = $adminImsConnection;
89+
$this->profile = $profile;
8390
$this->adminImsConfig = $adminImsConfig;
84-
$this->adminOrganizationService = $adminOrganizationService;
91+
$this->getOrganizations = $getOrganizations;
8592
$this->adminReauthProcessService = $adminReauthProcessService;
8693
$this->logger = $logger;
94+
$this->token = $token;
8795
}
8896

8997
/**
@@ -117,16 +125,16 @@ public function execute(): ResultInterface
117125
throw new AuthenticationException(__('An authentication error occurred. Verify and try again.'));
118126
}
119127

120-
$tokenResponse = $this->adminImsConnection->getTokenResponse($code);
128+
$tokenResponse = $this->token->getTokenResponse($code);
121129
$accessToken = $tokenResponse->getAccessToken();
122130

123-
$profile = $this->adminImsConnection->getProfile($accessToken);
131+
$profile = $this->profile->getProfile($accessToken);
124132
if (empty($profile['email'])) {
125133
throw new AuthenticationException(__('An authentication error occurred. Verify and try again.'));
126134
}
127135

128136
//check membership in organization
129-
$this->adminOrganizationService->checkOrganizationMembership($accessToken);
137+
$this->getOrganizations->checkOrganizationMembership($accessToken);
130138

131139
$this->adminReauthProcessService->execute($tokenResponse);
132140

0 commit comments

Comments
 (0)