Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,18 @@
*/
'token_auth_enforced' => false,

/**
* The interval at which token activity should be updated.
* Increasing this value means that the last activty on the security page gets
* more outdated.
*
* Tokens are still checked every 5 minutes for validity
* max value: 300
*
* Defaults to ``300``
*/
'token_auth_activity_update' => 60,

/**
* Whether the bruteforce protection shipped with Nextcloud should be enabled or not.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,13 @@ public function updateTokenActivity(IToken $token) {
if (!($token instanceof PublicKeyToken)) {
throw new InvalidTokenException("Invalid token type");
}

$activityInterval = $this->config->getSystemValueInt('token_auth_activity_update', 60);
$activityInterval = min(max($activityInterval, 0), 300);

/** @var DefaultToken $token */
$now = $this->time->getTime();
if ($token->getLastActivity() < ($now - 60)) {
if ($token->getLastActivity() < ($now - $activityInterval)) {
// Update token only once per minute
$token->setLastActivity($now);
$this->mapper->update($token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ public function testUpdateToken() {

public function testUpdateTokenDebounce() {
$tk = new PublicKeyToken();

$this->config->method('getSystemValueInt')
->willReturnCallback(function ($value, $default) {
return $default;
});

$tk->setLastActivity($this->time - 30);
$this->mapper->expects($this->never())
->method('update')
Expand Down