Skip to content

Commit 6c86ce4

Browse files
committed
fix(dav): cleanup of code no longer needed
Signed-off-by: Enrique Pérez Arnaud <enrique@cazalla.net>
1 parent 21029c7 commit 6c86ce4

2 files changed

Lines changed: 11 additions & 36 deletions

File tree

apps/dav/lib/Connector/Sabre/BearerAuth.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ public function validateBearerToken($bearerToken) {
4747
\OC_Util::setupFS();
4848
$this->token = $bearerToken;
4949

50+
// public.php sets incognito mode for anonymous share access, which makes
51+
// Session::getUser() return null and consequently Session::isLoggedIn()
52+
// return false even after a successful token login. Disable it here so
53+
// the logged-in user is visible for the rest of the request. If the
54+
// bearer token is invalid and Sabre falls back to one of the public
55+
// auth backends, that backend will re-enable incognito mode itself.
56+
\OC_User::setIncognitoMode(false);
57+
5058
if (!$this->userSession->isLoggedIn()) {
5159
$this->userSession->tryTokenLogin($this->request);
5260
}

lib/private/User/Session.php

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -617,35 +617,14 @@ private function loginWithToken($token) {
617617
// Ignore and use empty string instead
618618
}
619619

620+
$this->manager->emit('\OC\User', 'preLogin', [$dbToken->getLoginName(), $password]);
621+
620622
$user = $this->manager->get($uid);
621623
if (is_null($user)) {
622-
// Maybe this is an access token. We keep the refresh tokens as UID of access tokens
623-
try {
624-
$token = $uid;
625-
$dbToken = $this->tokenProvider->getToken($token);
626-
} catch (InvalidTokenException $ex) {
627-
return false;
628-
}
629-
$uid = $dbToken->getUID();
630-
631-
// When logging in with token, the password must be decrypted first before passing to login hook
632-
$password = '';
633-
try {
634-
$password = $this->tokenProvider->getPassword($dbToken, $token);
635-
} catch (PasswordlessTokenException $ex) {
636-
// Ignore and use empty string instead
637-
}
638624
// user does not exist
639-
$user = $this->manager->get($uid);
640-
if (is_null($user)) {
641-
return false;
642-
}
625+
return false;
643626
}
644627

645-
$this->manager->emit('\OC\User', 'preLogin', [$dbToken->getLoginName(), $password]);
646-
647-
// See line 173 in this module, needed for completeLogin
648-
OC_User::setIncognitoMode(false);
649628
return $this->completeLogin(
650629
$user,
651630
[
@@ -867,30 +846,18 @@ public function tryTokenLogin(IRequest $request) {
867846
return false;
868847
}
869848

870-
return $this->doTryTokenLogin($token);
871-
}
872-
873-
private function doTryTokenLogin(string $token): bool {
874849
if (!$this->loginWithToken($token)) {
875850
return false;
876851
}
877852
if (!$this->validateToken($token)) {
878853
return false;
879854
}
880855

881-
try {
882-
$dbToken = $this->tokenProvider->getToken($token);
883-
} catch (InvalidTokenException $e) {
884-
// Can't really happen but better save than sorry
885-
return true;
886-
}
887-
888856
// Set the session variable so we know this is an app password
889857
if ($dbToken instanceof PublicKeyToken && $dbToken->getType() === IToken::PERMANENT_TOKEN) {
890858
$this->session->set('app_password', $token);
891859
} elseif ($dbToken instanceof PublicKeyToken && $dbToken->getType() === IToken::ONETIME_TOKEN) {
892860
$this->tokenProvider->invalidateTokenById($dbToken->getUID(), $dbToken->getId());
893-
$request = \OCP\Server::get(IRequest::class);
894861
if ($request->getPathInfo() !== '/core/getapppassword-onetime') {
895862
return false;
896863
}

0 commit comments

Comments
 (0)