diff --git a/apps/dav/lib/Connector/Sabre/BearerAuth.php b/apps/dav/lib/Connector/Sabre/BearerAuth.php
index b38600bd94431..9a423bebd63a9 100644
--- a/apps/dav/lib/Connector/Sabre/BearerAuth.php
+++ b/apps/dav/lib/Connector/Sabre/BearerAuth.php
@@ -21,6 +21,7 @@
* along with this program. If not, see .
*
*/
+
namespace OCA\DAV\Connector\Sabre;
use OCP\IRequest;
@@ -62,10 +63,7 @@ private function setupUserFs($userId) {
public function validateBearerToken($bearerToken) {
\OC_Util::setupFS();
- if (!$this->userSession->isLoggedIn()) {
- $this->userSession->tryTokenLogin($this->request);
- }
- if ($this->userSession->isLoggedIn()) {
+ if ($this->userSession->tryTokenLogin($this->request)) {
return $this->setupUserFs($this->userSession->getUser()->getUID());
}
diff --git a/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php b/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php
index bfc8d9f9c53c6..510c8d1ea8f89 100644
--- a/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php
+++ b/apps/dav/tests/unit/Connector/Sabre/BearerAuthTest.php
@@ -22,6 +22,7 @@
* along with this program. If not, see .
*
*/
+
namespace OCA\DAV\Tests\unit\Connector\Sabre;
use OCA\DAV\Connector\Sabre\BearerAuth;
@@ -66,12 +67,9 @@ public function testValidateBearerTokenNotLoggedIn(): void {
public function testValidateBearerToken(): void {
$this->userSession
- ->expects($this->exactly(2))
- ->method('isLoggedIn')
- ->willReturnOnConsecutiveCalls(
- false,
- true,
- );
+ ->expects($this->once())
+ ->method('tryTokenLogin')
+ ->willReturn(true);
$user = $this->createMock(IUser::class);
$user
->expects($this->once())