diff options
author | Raul <raul@nextcloud.com> | 2022-04-26 20:32:16 +0300 |
---|---|---|
committer | Raul <raul@nextcloud.com> | 2022-04-26 20:32:16 +0300 |
commit | 673503f39d3b0ec06168b682785cc8fc3ec67b5e (patch) | |
tree | 515a44ad74b0b37017fdd3b98d92a13dba3e9ecc /lib | |
parent | 10235f21d84e69159b6b3e8d9317177465304594 (diff) |
Add token_ttl app configenh/config_value/ttl
Signed-off-by: Raul <raul@nextcloud.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AppConfig.php | 2 | ||||
-rw-r--r-- | lib/Db/WopiMapper.php | 27 |
2 files changed, 20 insertions, 9 deletions
diff --git a/lib/AppConfig.php b/lib/AppConfig.php index 9a9bec66..c983c7c8 100644 --- a/lib/AppConfig.php +++ b/lib/AppConfig.php @@ -27,7 +27,7 @@ class AppConfig { 'watermark_allGroupsList' => [], 'watermark_allTagsList' => [], 'watermark_linkTagsList' => [], - + 'token_ttl' => 36000, // 10 hours ]; const WATERMARK_APP_NAMESPACE = 'files'; diff --git a/lib/Db/WopiMapper.php b/lib/Db/WopiMapper.php index e725177d..025719c1 100644 --- a/lib/Db/WopiMapper.php +++ b/lib/Db/WopiMapper.php @@ -22,6 +22,7 @@ */ namespace OCA\Richdocuments\Db; +use OCA\Richdocuments\AppConfig; use OCA\Richdocuments\Exceptions\ExpiredTokenException; use OCA\Richdocuments\Exceptions\UnknownTokenException; use OCP\AppFramework\Db\TokenExpiredException; @@ -32,11 +33,6 @@ use OCP\ILogger; use OCP\Security\ISecureRandom; class WopiMapper extends Mapper { - // Tokens expire after this many seconds. - // 10 hours is the recommended value on the spec doc: - // https://docs.microsoft.com/en-us/microsoft-365/cloud-storage-partner-program/rest/concepts#access_token_ttl - const TOKEN_LIFETIME_SECONDS = 36000; - /** @var ISecureRandom */ private $random; @@ -46,15 +42,20 @@ class WopiMapper extends Mapper { /** @var ITimeFactory */ private $timeFactory; + /** @var AppConfig */ + private $appConfig; + public function __construct(IDBConnection $db, ISecureRandom $random, ILogger $logger, - ITimeFactory $timeFactory) { + ITimeFactory $timeFactory, + AppConfig $appConfig) { parent::__construct($db, 'richdocuments_wopi', Wopi::class); $this->random = $random; $this->logger = $logger; $this->timeFactory = $timeFactory; + $this->appConfig = $appConfig; } /** @@ -79,7 +80,7 @@ class WopiMapper extends Mapper { 'canwrite' => $updatable, 'serverHost' => $serverHost, 'token' => $token, - 'expiry' => $this->timeFactory->getTime() + self::TOKEN_LIFETIME_SECONDS, + 'expiry' => $this->calculateNewTokenExpiry(), 'guestDisplayname' => $guestDisplayname, 'templateDestination' => $templateDestination, 'hideDownload' => $hideDownload, @@ -104,7 +105,7 @@ class WopiMapper extends Mapper { 'fileid' => 0, 'editorUid' => $uid, 'token' => $token, - 'expiry' => $this->timeFactory->getTime() + self::TOKEN_LIFETIME_SECONDS, + 'expiry' => $this->calculateNewTokenExpiry(), 'remoteServer' => $remoteServer, 'tokenType' => Wopi::TOKEN_TYPE_INITIATOR ]); @@ -166,4 +167,14 @@ class WopiMapper extends Mapper { return $wopi; } + + /** + * Calculates the expiry TTL for a newly created token. + * + * @return int + */ + private function calculateNewTokenExpiry(): int + { + return $this->timeFactory->getTime() + (int) $this->appConfig->getAppValue('token_ttl'); + } } |