Skip to content
Open
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
29 changes: 0 additions & 29 deletions lib/User/Backend.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Server;
use OCP\User\Backend\ABackend;
use OCP\User\Backend\ICountUsersBackend;
Expand Down Expand Up @@ -369,12 +368,10 @@ public function getCurrentUserId(): string {
}

$this->session->set('last-password-confirm', $this->timeFactory->getTime() + 4 * 365 * 24 * 3600);
$this->setSessionUser($userId);
return $userId;
} elseif ($this->userExists($tokenUserId)) {
$this->checkFirstLogin($tokenUserId);
$this->session->set('last-password-confirm', $this->timeFactory->getTime() + 4 * 365 * 24 * 3600);
$this->setSessionUser($tokenUserId);
return $tokenUserId;
} else {
// check if the user exists locally
Expand All @@ -396,7 +393,6 @@ public function getCurrentUserId(): string {
}
$this->checkFirstLogin($tokenUserId);
$this->session->set('last-password-confirm', $this->timeFactory->getTime() + 4 * 365 * 24 * 3600);
$this->setSessionUser($tokenUserId);
return $tokenUserId;
}
}
Expand All @@ -417,31 +413,6 @@ private function isAcceptableUserId(mixed $userId): bool {
return is_string($userId) && $userId !== '' && trim($userId) !== '';
}

/**
* Set the user in IUserSession after bearer token validation.
* Without this, DI-injected $userId is null in OCS controllers
* and CalDAV plugins, causing 500 errors in Deck, Talk, and Tasks.
*
* Note: IUserSession is resolved via Server::get() rather than constructor
* injection to avoid a circular dependency (IUserSession depends on this Backend).
*/
private function setSessionUser(string $userId): void {
try {
$userSession = Server::get(IUserSession::class);
$currentUser = $userSession->getUser();

// Only fetch and set if the session doesn't already have this user
if ($currentUser === null || $currentUser->getUID() !== $userId) {
$user = $this->userManager->get($userId);
if ($user !== null) {
$userSession->setUser($user);
}
}
} catch (\Throwable $e) {
$this->logger->debug('Failed to set session user after bearer validation: ' . $e->getMessage());
}
}

/**
*
* Performs first-login initialisation (home folder setup, skeleton copy, events)
Expand Down