Skip to content

Commit cd3dba8

Browse files
committed
AC-1619: Integration access tokens do not work as Bearer tokens
1 parent cee02f6 commit cd3dba8

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

app/code/Magento/Integration/Model/OpaqueToken/Reader.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use Magento\Integration\Helper\Oauth\Data as OauthHelper;
2121

2222
/**
23+
* Reads user token data
24+
*
2325
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2426
*/
2527
class Reader implements UserTokenReaderInterface
@@ -112,6 +114,7 @@ private function getTokenModel(string $token): Token
112114
* Validate the given user type
113115
*
114116
* @param int $userType
117+
* @throws UserTokenException
115118
*/
116119
private function validateUserType(int $userType): void
117120
{

app/code/Magento/Integration/Model/UserToken/ExpirationValidator.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,30 @@ public function __construct(DtUtil $datetimeUtil)
3434
*/
3535
public function validate(UserToken $token): void
3636
{
37-
if ($token->getUserContext()->getUserType() !== UserContextInterface::USER_TYPE_INTEGRATION
38-
&& $token->getData()->getExpires()->getTimestamp() <= $this->datetimeUtil->gmtTimestamp()
39-
) {
37+
if (!$this->isIntegrationToken($token) && $this->isTokenExpired($token)) {
4038
throw new AuthorizationException(__('Consumer key has expired'));
4139
}
4240
}
41+
42+
/**
43+
* Check if a token is expired
44+
*
45+
* @param UserToken $token
46+
* @return bool
47+
*/
48+
private function isTokenExpired(UserToken $token): bool
49+
{
50+
return $token->getData()->getExpires()->getTimestamp() <= $this->datetimeUtil->gmtTimestamp();
51+
}
52+
53+
/**
54+
* Check if a token is an integration token
55+
*
56+
* @param UserToken $token
57+
* @return bool
58+
*/
59+
private function isIntegrationToken(UserToken $token): bool
60+
{
61+
return $token->getUserContext()->getUserType() === UserContextInterface::USER_TYPE_INTEGRATION;
62+
}
4363
}

0 commit comments

Comments
 (0)