Skip to content

Commit 3cf4445

Browse files
committed
Merge remote-tracking branch 'origin/BUG#AC-9337' into spartans_pr_06062024
2 parents ef6d047 + 4cbacf9 commit 3cf4445

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

app/code/Magento/Integration/Api/TokenManager.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,15 @@ public function revokeFor(UserContextInterface $userContext): void
9494
{
9595
$this->tokenRevoker->revokeFor($userContext);
9696
}
97+
98+
/**
99+
* Revoke previously issued tokens for given user.
100+
*
101+
* @param UserContextInterface $userContext
102+
* @return void
103+
*/
104+
public function revokeForOld(UserContextInterface $userContext): void
105+
{
106+
$this->tokenRevoker->revokeForOld($userContext);
107+
}
97108
}

app/code/Magento/Integration/Model/CustomerTokenService.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public function createCustomerAccessToken($username, $password)
7777
CustomUserContext::USER_TYPE_CUSTOMER
7878
);
7979
$params = $this->tokenManager->createUserTokenParameters();
80+
$this->revokeCustomerAccessTokenOld($customerDataObject->getId());
8081

8182
return $this->tokenManager->create($context, $params);
8283
}
@@ -114,4 +115,23 @@ private function getRequestThrottler()
114115
}
115116
return $this->requestThrottler;
116117
}
118+
119+
/**
120+
* Revoke old token by customer id.
121+
*
122+
* @param int $customerId
123+
* @return bool
124+
* @throws \Magento\Framework\Exception\LocalizedException
125+
*/
126+
public function revokeCustomerAccessTokenOld($customerId)
127+
{
128+
try {
129+
$this->tokenManager->revokeForOld(
130+
new CustomUserContext((int)$customerId, CustomUserContext::USER_TYPE_CUSTOMER)
131+
);
132+
} catch (UserTokenException $exception) {
133+
throw new LocalizedException(__('Failed to revoke customer\'s access tokens'), $exception);
134+
}
135+
return true;
136+
}
117137
}

app/code/Magento/JwtUserToken/Model/Revoker.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,15 @@ public function revokeFor(UserContextInterface $userContext): void
3939
new Revoked((int) $userContext->getUserType(), (int) $userContext->getUserId(), time())
4040
);
4141
}
42+
43+
/**
44+
* @inheritDoc
45+
*/
46+
public function revokeForOld(UserContextInterface $userContext): void
47+
{
48+
//Invalidating all tokens issued before current datetime.
49+
$this->revokedRepo->saveRevoked(
50+
new Revoked((int) $userContext->getUserType(), (int) $userContext->getUserId(), time()-1)
51+
);
52+
}
4253
}

0 commit comments

Comments
 (0)