Skip to content

Commit 82745db

Browse files
Cari Spruiellisitnikov
authored andcommitted
MAGETWO-51292: [GITHUB] OAuth Token Exchange Expiration Period Is Not Calculated Correctly #3449
- change consumer expiration to be based on time token exchange starts instead of when consumer is created
1 parent 926385c commit 82745db

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

app/code/Magento/Integration/Model/Oauth/Consumer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,6 @@ public function getCreatedAt()
176176
public function isValidForTokenExchange()
177177
{
178178
$expiry = $this->dataHelper->getConsumerExpirationPeriod();
179-
return $expiry > $this->getResource()->getTimeInSecondsSinceCreation($this->getId());
179+
return $expiry > $this->getResource()->getTimeInSecondsSinceTokenExchangeStarted($this->getId());
180180
}
181181
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ public function postToConsumer($consumerId, $endpointUrl)
193193
{
194194
try {
195195
$consumer = $this->_consumerFactory->create()->load($consumerId);
196+
$consumer->setUpdatedAt(date_create());
197+
$consumer->save();
196198
if (!$consumer->getId()) {
197199
throw new \Magento\Framework\Oauth\Exception(
198200
__('A consumer with ID %1 does not exist', $consumerId)

app/code/Magento/Integration/Model/ResourceModel/Oauth/Consumer.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,16 @@ public function getTimeInSecondsSinceCreation($consumerId)
5959

6060
return $connection->fetchOne($select);
6161
}
62+
63+
public function getTimeInSecondsSinceTokenExchangeStarted($consumerId)
64+
{
65+
$connection = $this->getConnection();
66+
$select = $connection->select()
67+
->from($this->getMainTable())
68+
->reset(\Magento\Framework\DB\Select::COLUMNS)
69+
->columns(new \Zend_Db_Expr('CURRENT_TIMESTAMP() - updated_at'))
70+
->where('entity_id = ?', $consumerId);
71+
72+
return $connection->fetchOne($select);
73+
}
6274
}

0 commit comments

Comments
 (0)