2018-05-16 04:35:18 -04:00
|
|
|
<?php
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2018-12-07 07:40:43 -05:00
|
|
|
declare(strict_types=1);
|
2019-12-03 13:57:53 -05:00
|
|
|
|
2018-05-16 04:35:18 -04:00
|
|
|
/**
|
2024-05-30 14:13:41 -04:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2018-05-16 04:35:18 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\OAuth2\Migration;
|
|
|
|
|
|
|
|
|
|
use OC\Authentication\Token\IProvider as TokenProvider;
|
|
|
|
|
use OCA\OAuth2\Db\AccessToken;
|
|
|
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
2024-01-04 06:20:14 -05:00
|
|
|
use OCP\Authentication\Exceptions\InvalidTokenException;
|
2018-05-16 04:35:18 -04:00
|
|
|
use OCP\IDBConnection;
|
|
|
|
|
use OCP\Migration\IOutput;
|
|
|
|
|
use OCP\Migration\IRepairStep;
|
|
|
|
|
|
|
|
|
|
class SetTokenExpiration implements IRepairStep {
|
|
|
|
|
|
2024-10-17 09:42:21 -04:00
|
|
|
public function __construct(
|
|
|
|
|
private IDBConnection $connection,
|
2024-10-18 06:04:22 -04:00
|
|
|
private ITimeFactory $time,
|
2024-10-17 09:42:21 -04:00
|
|
|
private TokenProvider $tokenProvider,
|
|
|
|
|
) {
|
2018-05-16 04:35:18 -04:00
|
|
|
}
|
|
|
|
|
|
2018-12-07 07:40:43 -05:00
|
|
|
public function getName(): string {
|
2018-05-16 04:35:18 -04:00
|
|
|
return 'Update OAuth token expiration times';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function run(IOutput $output) {
|
|
|
|
|
$qb = $this->connection->getQueryBuilder();
|
|
|
|
|
$qb->select('*')
|
|
|
|
|
->from('oauth2_access_tokens');
|
|
|
|
|
|
2024-10-17 09:42:21 -04:00
|
|
|
$cursor = $qb->executeQuery();
|
2018-05-16 04:35:18 -04:00
|
|
|
|
|
|
|
|
while ($row = $cursor->fetch()) {
|
|
|
|
|
$token = AccessToken::fromRow($row);
|
|
|
|
|
try {
|
|
|
|
|
$appToken = $this->tokenProvider->getTokenById($token->getTokenId());
|
|
|
|
|
$appToken->setExpires($this->time->getTime() + 3600);
|
|
|
|
|
$this->tokenProvider->updateToken($appToken);
|
|
|
|
|
} catch (InvalidTokenException $e) {
|
|
|
|
|
//Skip this token
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$cursor->closeCursor();
|
|
|
|
|
}
|
|
|
|
|
}
|