Skip to content

Commit 1281933

Browse files
committed
CABPI-324: Change Org check to use new endpoint
1 parent 57a850d commit 1281933

File tree

2 files changed

+12
-25
lines changed

2 files changed

+12
-25
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,18 @@ public function execute(): Redirect
9898
throw new AuthenticationException(__('An authentication error occurred. Verify and try again.'));
9999
}
100100

101+
//get token from response
101102
$tokenResponse = $this->adminImsConnection->getTokenResponse($code);
103+
$accessToken = $tokenResponse->getAccessToken();
102104

103-
$profile = $this->adminImsConnection->getProfile($tokenResponse->getAccessToken());
105+
//check organization assignment
106+
$this->adminOrganizationService->checkOrganizationAllocation($accessToken);
107+
108+
//get profile info to check email
109+
$profile = $this->adminImsConnection->getProfile($accessToken);
104110
if (empty($profile['email'])) {
105111
throw new AuthenticationException(__('An authentication error occurred. Verify and try again.'));
106112
}
107-
$this->adminOrganizationService->checkOrganizationAllocation($profile);
108113
$this->adminLoginProcessService->execute($tokenResponse, $profile);
109114
} catch (AdobeImsAuthorizationException $e) {
110115
$this->logger->error($e->getMessage());

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

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,44 +33,26 @@ public function __construct(
3333
}
3434

3535
/**
36-
* Check if profile is allocated to configured organization
36+
* Check if user is assigned to organization
3737
*
38-
* @param array $profile
38+
* @param string $token
3939
* @return bool
4040
* @throws AdobeImsOrganizationAuthorizationException
4141
*/
42-
public function checkOrganizationAllocation(array $profile): bool
42+
public function checkOrganizationAllocation(string $token): bool
4343
{
4444
$configuredOrganization = $this->adminImsConfig->getOrganizationId();
4545

4646
//@TODO CABPI-324: Change Org check to use new endpoint
47-
if (!$configuredOrganization) {
47+
if (!$configuredOrganization || !$token) {
4848
throw new AdobeImsOrganizationAuthorizationException(
49-
__('Profile is not assigned to defined organization.')
49+
__('User is not assigned to defined organization.')
5050
);
5151
}
5252

5353
return true;
5454
}
5555

56-
/**
57-
* Get list of assigned organizations of admin
58-
*
59-
* @param array $profileRoles
60-
* @return array
61-
* @throws AdobeImsOrganizationAuthorizationException
62-
*/
63-
private function getCustomerOrganizationList(array $profileRoles): array
64-
{
65-
$organizationList = [];
66-
foreach ($profileRoles as $role) {
67-
$organizationId = $this->validateAndExtractOrganizationId($role['organization']);
68-
$organizationList[$role['named_role']] = $organizationId;
69-
}
70-
71-
return $organizationList;
72-
}
73-
7456
/**
7557
* Check if OrganizationID matches pattern
7658
*

0 commit comments

Comments
 (0)