From 9b14de0950742b761504e0d00c303b551d06ceaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 25 Apr 2024 10:07:09 +0200 Subject: [PATCH 1/3] docs: Update token_auth_activity_update default value to match implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- config/config.sample.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.sample.php b/config/config.sample.php index fa9f178524b20..9818921f9229d 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -355,7 +355,7 @@ * Tokens are still checked every 5 minutes for validity * max value: 300 * - * Defaults to ``300`` + * Defaults to ``60`` */ 'token_auth_activity_update' => 60, From 41528b1541b2b10a895ef0cd3334dee5c0accf0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Thu, 25 Apr 2024 10:07:54 +0200 Subject: [PATCH 2/3] fix: Always set last activity if we update the row of an authtoken anyways MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/private/Authentication/Token/PublicKeyTokenProvider.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/private/Authentication/Token/PublicKeyTokenProvider.php b/lib/private/Authentication/Token/PublicKeyTokenProvider.php index 3a15ba006d461..ea1e5484dda7b 100644 --- a/lib/private/Authentication/Token/PublicKeyTokenProvider.php +++ b/lib/private/Authentication/Token/PublicKeyTokenProvider.php @@ -308,6 +308,8 @@ public function updateToken(OCPIToken $token) { if (!($token instanceof PublicKeyToken)) { throw new InvalidTokenException("Invalid token type"); } + $now = $this->time->getTime(); + $token->setLastActivity($now); $this->mapper->update($token); $this->cacheToken($token); } From 9880800aeeeae3d106f0bb3e82d98a65b8b77d00 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Tue, 21 May 2024 07:55:01 +0200 Subject: [PATCH 3/3] fix(auth): Update authtoken activity selectively Signed-off-by: Christoph Wurst --- lib/private/Authentication/Token/PublicKeyTokenProvider.php | 2 -- lib/private/User/Session.php | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/private/Authentication/Token/PublicKeyTokenProvider.php b/lib/private/Authentication/Token/PublicKeyTokenProvider.php index ea1e5484dda7b..3a15ba006d461 100644 --- a/lib/private/Authentication/Token/PublicKeyTokenProvider.php +++ b/lib/private/Authentication/Token/PublicKeyTokenProvider.php @@ -308,8 +308,6 @@ public function updateToken(OCPIToken $token) { if (!($token instanceof PublicKeyToken)) { throw new InvalidTokenException("Invalid token type"); } - $now = $this->time->getTime(); - $token->setLastActivity($now); $this->mapper->update($token); $this->cacheToken($token); } diff --git a/lib/private/User/Session.php b/lib/private/User/Session.php index 88359877d7c7f..05c2436ce41eb 100644 --- a/lib/private/User/Session.php +++ b/lib/private/User/Session.php @@ -43,6 +43,7 @@ use OC\Authentication\Exceptions\PasswordLoginForbiddenException; use OC\Authentication\Token\IProvider; use OC\Authentication\Token\IToken; +use OC\Authentication\Token\PublicKeyToken; use OC\Hooks\Emitter; use OC\Hooks\PublicEmitter; use OC_User; @@ -774,6 +775,9 @@ private function checkTokenCredentials(IToken $dbToken, $token) { } $dbToken->setLastCheck($now); + if ($dbToken instanceof PublicKeyToken) { + $dbToken->setLastActivity($now); + } $this->tokenProvider->updateToken($dbToken); return true; }